public static void ChangeTheme(Window window, Accent newAccent, Theme newTheme)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }
            Tuple <Theme, Accent> oldThemeInfo = DetectTheme(window);

            ChangeTheme(window.Resources, oldThemeInfo, newAccent, newTheme);
        }
        public static void ChangeTheme(Application app, Accent newAccent, Theme newTheme)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            Tuple <Theme, Accent> oldThemeInfo = DetectTheme(app);

            ChangeTheme(app.Resources, oldThemeInfo, newAccent, newTheme);
        }
        public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }
            ResourceDictionary newRd = (newTheme == Theme.Light) ? LightResource : DarkResource;

            ApplyResourceDictionary(newAccent.Resources, resources);
            ApplyResourceDictionary(newRd, resources);
        }
        private static void ChangeTheme(ResourceDictionary resources, Tuple <Theme, Accent> oldThemeInfo, Accent newAccent, Theme newTheme)
        {
            bool flag = false;

            if (oldThemeInfo != null)
            {
                Func <ResourceDictionary, bool> predicate = null;
                Accent oldAccent = oldThemeInfo.Item2;
                if ((oldAccent != null) && (oldAccent.Name != newAccent.Name))
                {
                    if (predicate == null)
                    {
                        predicate = d => d.Source == oldAccent.Resources.Source;
                    }
                    ResourceDictionary item = resources.MergedDictionaries.FirstOrDefault <ResourceDictionary>(predicate);
                    if (item != null)
                    {
                        resources.MergedDictionaries.Add(newAccent.Resources);
                        resources.MergedDictionaries.Remove(item);
                        flag = true;
                    }
                }
                Theme theme = oldThemeInfo.Item1;
                if (theme != newTheme)
                {
                    ResourceDictionary oldThemeResource = (theme == Theme.Light) ? LightResource : DarkResource;
                    ResourceDictionary dictionary2      = resources.MergedDictionaries.FirstOrDefault <ResourceDictionary>(d => d.Source == oldThemeResource.Source);
                    if (dictionary2 != null)
                    {
                        ResourceDictionary dictionary3 = (newTheme == Theme.Light) ? LightResource : DarkResource;
                        resources.MergedDictionaries.Add(dictionary3);
                        resources.MergedDictionaries.Remove(dictionary2);
                        flag = true;
                    }
                }
            }
            else
            {
                ChangeTheme(resources, newAccent, newTheme);
                flag = true;
            }
            if (flag)
            {
                OnThemeChanged(newAccent, newTheme);
            }
        }
        internal static bool GetThemeFromResources(Theme presetTheme, ResourceDictionary dict, ref Tuple <Theme, Accent> detectedAccentTheme)
        {
            Theme  theme   = presetTheme;
            Accent accent  = null;
            Accent accent2 = null;

            accent2 = ((List <Accent>)DefaultAccents).Find(x => x.Resources.Source == dict.Source);
            if (accent2 != null)
            {
                accent = accent2;
                detectedAccentTheme = Tuple.Create <Theme, Accent>(theme, accent);
                return(true);
            }
            foreach (ResourceDictionary dictionary in dict.MergedDictionaries)
            {
                if (GetThemeFromResources(presetTheme, dictionary, ref detectedAccentTheme))
                {
                    return(true);
                }
            }
            return(false);
        }