Exemplo n.º 1
0
        public void SaveTheme(TerminalTheme theme)
        {
            _themes.WriteValueAsJson(theme.Id.ToString(), theme);

            if (theme.Id == GetCurrentThemeId())
            {
                CurrentThemeChanged?.Invoke(this, theme.Id);
            }
        }
Exemplo n.º 2
0
        // Behaviors
        public bool SetCurrentTheme(string name)
        {
            var theme = Themes.FirstOrDefault(t => t.Name == name);

            if (theme == null)
            {
                return(false);
            }

            CurrentTheme = theme;

            // add resource dictionary if not exist
            if (_applicationResourceDictionary == null)
            {
                _applicationResourceDictionary = new ResourceDictionary();
                Application.Current.Resources.MergedDictionaries.Add(_applicationResourceDictionary);
            }

            // begin update application and window resources
            _applicationResourceDictionary.BeginInit();
            _applicationResourceDictionary.MergedDictionaries.Clear();

            // get window resource dictionary
            var windowResourceDictionary = Application.Current.MainWindow.Resources.MergedDictionaries[0];

            windowResourceDictionary.BeginInit();
            windowResourceDictionary.MergedDictionaries.Clear();

            // load theme application resources
            foreach (var uri in theme.ApplicationResources)
            {
                _applicationResourceDictionary.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source = uri
                });
            }

            // load main window resources
            foreach (var uri in theme.MainWindowResources)
            {
                windowResourceDictionary.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source = uri
                });
            }

            // finish update
            _applicationResourceDictionary.EndInit();
            windowResourceDictionary.EndInit();

            // raise changed event
            CurrentThemeChanged?.Invoke(this, EventArgs.Empty);

            return(true);
        }
Exemplo n.º 3
0
 private static void OnThemeChange()
 {
     CurrentThemeChanged?.Invoke(null, EventArgs.Empty);
 }
Exemplo n.º 4
0
        public void SaveCurrentThemeId(Guid id)
        {
            _roamingSettings.SetValue(CurrentThemeKey, id);

            CurrentThemeChanged?.Invoke(this, id);
        }
Exemplo n.º 5
0
        public void SaveCurrentThemeId(Guid id)
        {
            _roamingSettings.Values[CurrentThemeKey] = id;

            CurrentThemeChanged?.Invoke(this, id);
        }