Esempio n. 1
0
        private static Theme ChangeTheme(ResourceDictionary resources, Theme oldTheme, Theme newTheme)
        {
            var themeChanged = false;

            if (oldTheme != newTheme)
            {
                resources.BeginInit();

                ResourceDictionary oldThemeResource = null;
                if (oldTheme.IsNotNull())
                {
                    oldThemeResource = resources.MergedDictionaries.FirstOrDefault(d => AreResourceDictionarySourcesEqual(d, oldTheme.Resources));
                }

                resources.MergedDictionaries.Add(newTheme.Resources);

                if (oldThemeResource.IsNotNull())
                {
                    resources.MergedDictionaries.Remove(oldThemeResource);
                }

                themeChanged = true;
                resources.EndInit();
            }

            if (themeChanged)
            {
                OnThemeChanged(newTheme);
            }

            return(newTheme);
        }