基本信息
源码名称:wpf皮肤切换 示例源码下载
源码大小:2.04M
文件格式:.zip
开发语言:C#
更新时间:2014-01-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
namespace WPF.Themes { using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Windows; using System.Windows.Controls; public static class ThemeManager { public static ResourceDictionary GetThemeResourceDictionary(string theme) { if (theme != null) { Assembly assembly = Assembly.LoadFrom("WPF.Themes.dll"); string packUri = String.Format(@"/WPF.Themes;component/{0}/Theme.xaml", theme); return Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary; } return null; } public static string[] GetThemes() { string[] themes = new string[] { "ExpressionDark", "ExpressionLight", //"RainierOrange", "RainierPurple", "RainierRadialBlue", "ShinyBlue", "ShinyRed", //"ShinyDarkTeal", "ShinyDarkGreen", "ShinyDarkPurple", "DavesGlossyControls", "WhistlerBlue", "BureauBlack", "BureauBlue", "BubbleCreme", "TwilightBlue", "UXMusingsRed", "UXMusingsGreen", //"UXMusingsRoughRed", "UXMusingsRoughGreen", "UXMusingsBubblyBlue" }; return themes; } public static void ApplyTheme(this Application app, string theme) { ResourceDictionary dictionary = ThemeManager.GetThemeResourceDictionary(theme); if (dictionary != null) { app.Resources.MergedDictionaries.Clear(); app.Resources.MergedDictionaries.Add(dictionary); } } public static void ApplyTheme(this ContentControl control, string theme) { ResourceDictionary dictionary = ThemeManager.GetThemeResourceDictionary(theme); if (dictionary != null) { control.Resources.MergedDictionaries.Clear(); control.Resources.MergedDictionaries.Add(dictionary); } } #region Theme /// <summary> /// Theme Attached Dependency Property /// </summary> public static readonly DependencyProperty ThemeProperty = DependencyProperty.RegisterAttached("Theme", typeof(string), typeof(ThemeManager), new FrameworkPropertyMetadata((string)string.Empty, new PropertyChangedCallback(OnThemeChanged))); /// <summary> /// Gets the Theme property. This dependency property /// indicates .... /// </summary> public static string GetTheme(DependencyObject d) { return (string)d.GetValue(ThemeProperty); } /// <summary> /// Sets the Theme property. This dependency property /// indicates .... /// </summary> public static void SetTheme(DependencyObject d, string value) { d.SetValue(ThemeProperty, value); } /// <summary> /// Handles changes to the Theme property. /// </summary> private static void OnThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { string theme = e.NewValue as string; if (theme == string.Empty) return; ContentControl control = d as ContentControl; if (control != null) { control.ApplyTheme(theme); } } #endregion } }