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;
            }
        }
    }
  • 相关阅读:
    Java Web 047: 处理商品列表的查询
    Java Web 047:开发商品列表的模板页
    Java Web 046: 处理登录成功后的跳转
    Java Web 045: 处理登录请求
    Java Web 044: 处理注册响应
    Java Web 043: 处理注册请求
    Java Web 042: 创建UserDao控制user的相关数据库操作
    Java Web 041: 创建数据模型和模拟数据库
    Java Web 03: MVC分层架构 / JavaEE分层架构 (图解)
    Java Web 02: 单例模式
  • 原文地址:https://www.cnblogs.com/tranw/p/6026168.html
Copyright © 2011-2022 走看看