예제 #1
0
        private void LoadProperties(bool action, bool isMock)
        {
            var instance = new ThemeConstantsEntity();

            foreach (var prop in typeof(ThemeConstantsEntity).GetProperties())
            {
                if (prop.CanRead)
                {
                    var value = prop.GetValue(instance, null) as ThemeEntity;

                    if (isMock)
                    {
                        if (string.Equals(_selectedTheme, value.ThemeName, StringComparison.OrdinalIgnoreCase))
                        {
                            ChangeMockTheme(value.ThemeSource);
                        }
                    }
                    else if (action)
                    {
                        ThemeComboBox.Items.Add(value.ThemeName);
                    }
                    else
                    {
                        if (string.Equals(_selectedTheme, value.ThemeName, StringComparison.OrdinalIgnoreCase))
                        {
                            Properties.Settings.Default["ApplicationTheme"] = value.ThemeName;
                            Properties.Settings.Default.Save();
                            ((App)Application.Current).ChangeTheme(value.ThemeSource);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void ApplyTheme()
        {
            var theme = new ThemeConstantsEntity();

            foreach (var prop in typeof(ThemeConstantsEntity).GetProperties())
            {
                if (prop.CanRead)
                {
                    var value            = prop.GetValue(theme, null) as ThemeEntity;
                    var applicationTheme = Properties.Settings.Default["ApplicationTheme"].ToString();
                    if (string.Equals(value.ThemeName, applicationTheme, StringComparison.OrdinalIgnoreCase))
                    {
                        var dictionaryUri = new Uri(value.ThemeSource, UriKind.Relative);
                        var resourceDict  = Application.LoadComponent(dictionaryUri) as ResourceDictionary;
                        Application.Current.Resources.MergedDictionaries.Clear();
                        Application.Current.Resources.MergedDictionaries.Add(resourceDict);
                    }
                }
            }
        }