public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }

            var themeResource = (newTheme == Theme.Light) ? LightResource : DarkResource;

            ApplyResourceDictionary(newAccent.Resources, resources);
            ApplyResourceDictionary(themeResource, resources);
        }
Exemple #2
0
 public static void ChangeTheme(Window window, Accent accent, Theme theme)
 {
     ChangeTheme(window.Resources, accent, theme);
 }
        private static void ChangeTheme(ResourceDictionary resources, Tuple <Theme, Accent> oldThemeInfo, Accent newAccent, Theme newTheme)
        {
            var themeChanged = false;

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

                        themeChanged = true;
                    }
                }

                var oldTheme = oldThemeInfo.Item1;
                if (oldTheme != null && oldTheme != newTheme)
                {
                    var oldThemeResource = (oldTheme == Theme.Light) ? LightResource : DarkResource;
                    var md = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldThemeResource.Source);
                    if (md != null)
                    {
                        var newThemeResource = (newTheme == Theme.Light) ? LightResource : DarkResource;
                        resources.MergedDictionaries.Add(newThemeResource);
                        var ok = resources.MergedDictionaries.Remove(md);

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

                themeChanged = true;
            }

            if (themeChanged)
            {
                OnThemeChanged(newAccent, newTheme);
            }
        }
Exemple #4
0
 public static void ChangeTheme(Application app, Accent accent, Theme theme)
 {
     ChangeTheme(app.Resources, accent, theme);
 }