コード例 #1
0
        /// <summary>
        /// Load a ThemeElement into the application dictionnaries
        /// </summary>
        /// <param name="themeResource"></param>
        public void LoadThemeResource(ThemeElement themeResource)
        {
            Tracer.Verbose("ThemeManager:LoadThemeResource", "START");

            //TraceDictionnaries();

            Application.Current.Resources.BeginInit();

            try
            {
                //unload the previous same resource type, load the new one
                LoadDictionaries(ThemeElements.Where(p => p.Group == themeResource.Group && p.IsSelected == true).First(),
                                 themeResource);
            }
            catch (Exception all)
            {
                Tracer.Error("ThemeManager.LoadThemeResource", all);
            }

            Application.Current.Resources.EndInit();

            //TraceDictionnaries();

            Tracer.Verbose("ThemeManager:LoadThemeResource", "END");
        }
コード例 #2
0
        /// <summary>
        /// Load the specified ThemeElement in the application and set it as IsSelected
        /// </summary>
        /// <param name="oldThemeResource"></param>
        /// <param name="newThemeResource"></param>
        private void LoadDictionaries(ThemeElement oldThemeResource, ThemeElement newThemeResource)
        {
            Tracer.Verbose("ThemeManager:LoadDictionaries", "START");
            try
            {
                try
                {
                    foreach (string dictionnary in oldThemeResource.Dictionaries)
                    {
                        ResourceDictionary dic = Application.Current.Resources.MergedDictionaries.FirstOrDefault(p => p.Source.OriginalString == dictionnary);
                        if (dic != null)
                        {
                            //does not exist in new ones
                            if (newThemeResource.Dictionaries.Where(p => p == dic.Source.OriginalString).Count() == 0)
                            {
                                Application.Current.Resources.MergedDictionaries.Remove(dic);
                            }
                        }
                    }
                    oldThemeResource.IsSelected = false;
                }
                catch (Exception all)
                {
                    Tracer.Error("ThemeManager.LoadDictionaries", all);
                }

                foreach (string dictionnary in newThemeResource.Dictionaries)
                {
                    //if does not exist in application
                    if (Application.Current.Resources.MergedDictionaries.Where(p => p.Source.OriginalString == dictionnary).Count() == 0)
                    {
                        Uri Source = new Uri(dictionnary, UriKind.Relative);
                        ResourceDictionary dico = (ResourceDictionary)Application.LoadComponent(Source);
                        dico.Source = Source;
                        Application.Current.Resources.MergedDictionaries.Add(dico);
                    }
                }
                newThemeResource.IsSelected = true;
            }
            catch (Exception all)
            {
                Tracer.Error("ThemeManager.LoadDictionaries", all);
            }
            Tracer.Verbose("ThemeManager:LoadDictionaries", "END");
        }
コード例 #3
0
 /// <summary>
 /// Load the specified ThemeElement in the application and set it as IsSelected
 /// </summary>
 /// <param name="themeResource"></param>
 private void LoadDictionaries(ThemeElement themeResource)
 {
     Tracer.Verbose("ThemeManager:LoadDictionaries", "START");
     try
     {
         foreach (string dictionnary in themeResource.Dictionaries)
         {
             if (Application.Current.Resources.MergedDictionaries.Where(p => p.Source.OriginalString == dictionnary).Count() == 0)
             {
                 Uri Source = new Uri(dictionnary, UriKind.Relative);
                 ResourceDictionary dico = (ResourceDictionary)Application.LoadComponent(Source);
                 dico.Source = Source;
                 Application.Current.Resources.MergedDictionaries.Add(dico);
             }
         }
         themeResource.IsSelected = true;
     }
     catch (Exception all)
     {
         Tracer.Error("ThemeManager.LoadDictionaries", all);
     }
     Tracer.Verbose("ThemeManager:LoadDictionaries", "END");
 }