private void CreateDefaultsSettings(ISettingsManager settings
                                            , IAppearanceManager appearance)
        {
            var themeInfos = settings.Themes;

            for (int i = 0; i < _WpfThemes.GetLength(0); i++)
            {
                var        item         = _WpfThemes[i];
                List <Uri> WpfResources = null;
                switch (item[1])
                {
                case "Light":
                    WpfResources = new List <Uri>(LightResources);
                    break;

                case "Dark":
                    WpfResources = new List <Uri>(DarkResources);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("WPF theme base:" + item[1] + " not supported.");
                }
                try
                {
                    // Combine resources into one consistent model
                    var theme = new ThemeDefinitionViewModel(item[0], WpfResources, item[2]);
                    themeInfos.AddThemeInfo(theme);
                }
                catch (Exception exc)
                {
                    Debug.WriteLine(exc.StackTrace);
                }
            }

            appearance.SetDefaultTheme(themeInfos, "Light"); // configure a default WPF theme

            try
            {
                // Create a general settings model to make sure the app is at least governed by defaults
                // if there are no customized settings on first ever start-up of application
                var options = settings.Options;

                SettingDefaults.CreateGeneralSettings(options);
                SettingDefaults.CreateAppearanceSettings(options, settings);

                settings.Options.SetUndirty();
            }
            catch
            {
                // Ignore issues in theme definition stage to ensure app starts up
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Standard Constructor
        /// </summary>
        public ThemeViewModel()
        {
            var settings = GetService <ISettingsManager>(); // add the default themes

            _ListOfThemes = new Dictionary <string, ThemeDefinitionViewModel>();

            foreach (var item in settings.Themes.GetThemeInfos())
            {
                var list = new List <string>();
                foreach (var subitem in item.ThemeSources)
                {
                    list.Add(subitem.ToString());
                }

                _ListOfThemes.Add(item.DisplayName, new ThemeDefinitionViewModel(new ThemeDefinition(item.DisplayName, list)));
            }

            // Lets make sure there is a default
            _ListOfThemes.TryGetValue(GetService <IAppearanceManager>().GetDefaultTheme().DisplayName, out _DefaultTheme);

            // and something sensible is selected
            _SelectedTheme            = _DefaultTheme;
            _SelectedTheme.IsSelected = true;
        }