コード例 #1
0
ファイル: ThemeManager.cs プロジェクト: qqzhw/HcdzManage
        public static void ChangeAppStyle(Window window, Accent newAccent, AppTheme newTheme)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            var oldTheme = DetectAppStyle(window);

            ChangeAppStyle(window.Resources, oldTheme, newAccent, newTheme);
        }
コード例 #2
0
ファイル: ThemeManager.cs プロジェクト: qqzhw/HcdzManage
        public static void ChangeAppStyle(Application app, Accent newAccent, AppTheme newTheme)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }

            var oldTheme = DetectAppStyle(app);

            ChangeAppStyle(app.Resources, oldTheme, newAccent, newTheme);
        }
コード例 #3
0
ファイル: ThemeManager.cs プロジェクト: qqzhw/HcdzManage
        public static void ChangeAppStyle(ResourceDictionary resources, Accent newAccent, AppTheme newTheme)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }
            if (newAccent == null)
            {
                throw new ArgumentNullException("newAccent");
            }
            if (newTheme == null)
            {
                throw new ArgumentNullException("newTheme");
            }

            ApplyResourceDictionary(newAccent.Resources, resources);
            ApplyResourceDictionary(newTheme.Resources, resources);
        }
コード例 #4
0
ファイル: ThemeManager.cs プロジェクト: qqzhw/HcdzManage
 private static void OnThemeChanged(Accent newAccent, AppTheme newTheme)
 {
     SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs {
         AppTheme = newTheme, Accent = newAccent
     });
 }
コード例 #5
0
ファイル: ThemeManager.cs プロジェクト: qqzhw/HcdzManage
        private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
        {
            var themeChanged = false;

            if (oldThemeInfo != null)
            {
                var oldAccent = oldThemeInfo.Item2;
                if (oldAccent != null && oldAccent.Name != newAccent.Name)
                {
                    var key = oldAccent.Resources.Source.ToString().ToLower();
                    var oldAccentResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key);
                    if (oldAccentResource != null)
                    {
                        resources.MergedDictionaries.Add(newAccent.Resources);
                        resources.MergedDictionaries.Remove(oldAccentResource);

                        themeChanged = true;
                    }
                }

                var oldTheme = oldThemeInfo.Item1;
                if (oldTheme != null && oldTheme != newTheme)
                {
                    var key = oldTheme.Resources.Source.ToString().ToLower();
                    var oldThemeResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key);
                    if (oldThemeResource != null)
                    {
                        resources.MergedDictionaries.Add(newTheme.Resources);
                        resources.MergedDictionaries.Remove(oldThemeResource);

                        themeChanged = true;
                    }
                }
            }
            else
            {
                ChangeAppStyle(resources, newAccent, newTheme);

                themeChanged = true;
            }

            if (themeChanged)
            {
                OnThemeChanged(newAccent, newTheme);
            }
        }