public void SaveTheme(TerminalTheme theme) { _themes.WriteValueAsJson(theme.Id.ToString(), theme); if (theme.Id == GetCurrentThemeId()) { CurrentThemeChanged?.Invoke(this, theme.Id); } }
// 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); }
private static void OnThemeChange() { CurrentThemeChanged?.Invoke(null, EventArgs.Empty); }
public void SaveCurrentThemeId(Guid id) { _roamingSettings.SetValue(CurrentThemeKey, id); CurrentThemeChanged?.Invoke(this, id); }
public void SaveCurrentThemeId(Guid id) { _roamingSettings.Values[CurrentThemeKey] = id; CurrentThemeChanged?.Invoke(this, id); }