/// <summary> /// loads themes from the Themes directory into a collection of ThemeWraps /// </summary> public void LoadThemes() { if (Directory.Exists(themePath)) { //lets do this the stoneage way for better exception handling themeList = new ObservableCollection <ThemeWrap>(); var files = Directory.EnumerateFiles(themePath, "*.json"); foreach (string file in files) { try { var theme = new ThemeWrap { Theme = JsonConvert.DeserializeObject <Theme>(File.ReadAllText(file, Encoding.UTF8)), //need to delete the themepath here so we just get the filename. maybe there is a better way to do this. Path = file.Replace(themePath + "\\", "") }; if (theme != null) { themeList.Add(theme); } } catch (JsonSerializationException e) { Console.WriteLine("couldn't deserialize theme: {0}", file); } catch (JsonReaderException e) { Console.WriteLine("Error parsing theme: {0}", file); } } } }
/// <summary> /// Changes the theme of the application and automatically stores it as the new default in the application properties /// </summary> /// <param name="wrap">The themeWrap that the theme should be changed to.</param> public void ChangeTheme(ThemeWrap wrap) { //save themepath in the application properties. SaveTheme(wrap.Path); var dict = wrap.Theme.toResourceDictionary(); foreach (var key in dict.Keys) { Application.Current.Resources[key] = dict[key]; } Console.WriteLine("Changed Theme to {0}", wrap.Theme.ThemeName.English); }
private static void ChangeTheme(ThemeWrap wrap) { //save path of the theme SaveTheme(wrap.Path); //change the theme to json file format to provide meta info about the themes var dict = wrap.Theme.toResourceDictionary(); foreach (var key in dict.Keys) { Application.Current.Resources[key] = dict[key]; } }
public static void SetTheme(ThemeWrap theme) { ChangeTheme(theme); }