zoukankan      html  css  js  c++  java
  • WPF 主题切换(Z)

    using System;
    using System.Windows;
    using Assergs.Windows;
    
    namespace XMLSpy.WPF.Util{
        /// <summary>
        /// ThemeSwitcher所使用的主题枚举
        /// </summary>
        [Flags]
        public enum ThemeEnum{
            CLASSIC = 1,
            ROYALE = 2,
            LUNA = 4,
            LUNA_HOMESTEAD = 8,
            LUNA_METALLIC = 16,
            /// <summary>
            /// Vista默认主题
            /// </summary>
            AERO = 32,
            /// <summary>
            /// Office2007主题
            /// </summary>
            OFFICE2007 = 64
        }
    
        /// <summary>
        /// Theme切换
        /// </summary>
        public class ThemeSwitcher{
            /// <summary>
            /// 切换Theme
            /// </summary>
            /// <param name="theme">Theme枚举</param>
            /// <param name="element">FrameworkElement对象</param>
            public static void SwitchTheme(ThemeEnum theme, FrameworkElement element){
                element.Resources.MergedDictionaries.Add(GetThemeResourceDictionary(theme));
            }
    
            //public static void UnloadTheme(ThemeEnum theme,FrameworkContentElement element) {
            //    element.Resources.MergedDictionaries.Remove(GetThemeResourceDictionary(theme));
            //}
    
            public static ResourceDictionary GetThemeResourceDictionary(ThemeEnum theme){
                Uri uri = null;
                //==================== OFFICE2007 ======================================
                //Assergs.Windows.dll
                //office2007
                if (theme == ThemeEnum.OFFICE2007){
                    return new OfficeStyle();
                }
    
    
                switch (theme){
                        //==================== CLASSIC ======================================
                        //C:Program FilesReference AssembliesMicrosoftFrameworkv3.0PresentationFramework.Classic.dll
                        //classic
                    case ThemeEnum.CLASSIC:
                        uri =
                            new Uri(
                                "/PresentationFramework.Classic, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/classic.xaml",
                                UriKind.Relative);
    
                        break;
                        //==================== ROYALE ======================================
                        //C:Program FilesReference AssembliesMicrosoftFrameworkv3.0PresentationFramework.Royale.dll
                        //royale.normalcolor
                    case ThemeEnum.ROYALE:
                        uri =
                            new Uri(
                                "/PresentationFramework.Royale, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/royale.normalcolor.xaml",
                                UriKind.Relative);
                        break;
                        //==================== LUNA ======================================
                        //C:Program FilesReference AssembliesMicrosoftFrameworkv3.0PresentationFramework.Luna.dll
                        //luna.normalcolor
                    case ThemeEnum.LUNA:
                        uri =
                            new Uri(
                                "/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/luna.normalcolor.xaml",
                                UriKind.Relative);
                        break;
                        //luna.homestead
                    case ThemeEnum.LUNA_HOMESTEAD:
                        uri =
                            new Uri(
                                "/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/luna.homestead.xaml",
                                UriKind.Relative);
                        break;
                        //luna.metallic
                    case ThemeEnum.LUNA_METALLIC:
                        uri =
                            new Uri(
                                "/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/luna.metallic.xaml",
                                UriKind.Relative);
                        break;
                        //==================== AERO ======================================
                        //C:Program FilesReference AssembliesMicrosoftFrameworkv3.0PresentationFramework.Aero.dll
                        //aero.normalcolor
                    case ThemeEnum.AERO:
                        uri =
                            new Uri(
                                "/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml",
                                UriKind.Relative);
                        break;
                }
                return Application.LoadComponent(uri) as ResourceDictionary;
            }
        }
    }
  • 相关阅读:
    跨平台加密版 SQLite 3 wxSQLite3
    jQuery2011年年度最佳插件
    jQ中文API离线版下载(适用版本1.4.4,1.5,1.5.1,1.5.2,1.6,1.6.1,1.6.2)
    sql2000无法执行查询及未找到提供程序解决办法
    哈里斯Harris发射机状态监控和控制
    vs2019 最近的项目 所在文件
    QT从入门到入土 vs2019+qt插件
    Asp.Net WebApi swagger使用教程
    Nport 5110 资料
    C/C++ Qt 图形化开发
  • 原文地址:https://www.cnblogs.com/tranw/p/6026168.html
Copyright © 2011-2022 走看看