예제 #1
0
 /// <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);
             }
         }
     }
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
        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];
            }
        }
예제 #4
0
 public static void SetTheme(ThemeWrap theme)
 {
     ChangeTheme(theme);
 }