Exemplo n.º 1
0
 /// <summary>
 /// Removes the theme.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="theme">The theme.</param>
 public static void RemoveTheme(FrameworkElement source, Theme theme)
 {
     if (null == theme) return;
     if (null == source) return;
     lock (LoadedThemes)
     {
         ResourceDictionary dict;
         if (!LoadedThemes.TryGetValue(theme.UniqueId, out dict)) return;
         source.Resources.MergedDictionaries.Remove(dict);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Applies the theme.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="theme">The theme.</param>
 public static void ApplyTheme(FrameworkElement target, Theme theme)
 {
     if (null == theme) return;
     if (null == target) return;
     try
     {
         lock (LoadedThemes)
         {
             ResourceDictionary dict;
             var resource = theme.GetResourceLocation();
             var sourceAssembly = theme.GetType().Assembly;
             if (!LoadedThemes.TryGetValue(theme.UniqueId, out dict))
             {
                 dict = new ResourceDictionary {Source = RuntimeHelper.MakePackUri(sourceAssembly, resource)};
                 LoadedThemes.Add(theme.UniqueId, dict);
             }
             else
                 //target.Resources.MergedDictionaries.Remove(dict);
                 return;
             target.Resources.MergedDictionaries.Add(dict);
             RuntimeCommon.DefaultLogger.Log(LogLevel.Information, null, string.Format("Applied theme: {0}", theme));
         }
     }
     catch (Exception e)
     {
         RuntimeCommon.DefaultLogger.Log(LogLevel.Error, null, e.ToString());
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Removes the theme.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="theme">The theme.</param>
 public void RemoveTheme(ResourceDictionary source, Theme theme)
 {
     source.Guard("source");
     theme.Guard("theme");
     lock (LoadedThemes)
     {
         ResourceDictionary dict;
         if (!LoadedThemes.TryGetValue(theme.UniqueId, out dict))
             return;
         source.MergedDictionaries.Remove(dict);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the theme.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="value">The value.</param>
 public static void SetTheme(FrameworkElement element, Theme value)
 {
     element.SetValue(ThemeProperty, value);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Applies the theme.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="theme">The theme.</param>
 public void ApplyTheme(ResourceDictionary target, Theme theme)
 {
     target.Guard("target");
     theme.Guard("theme");
     lock (LoadedThemes)
     {
         ResourceDictionary dict;
         RemoveTheme(target, theme);
         if (!LoadedThemes.TryGetValue(theme.UniqueId, out dict))
         {
             var resource = theme.GetResourceLocation();
             var sourceAssembly = theme.GetType().Assembly;
             var pack = RuntimeHelper.MakePackUri(sourceAssembly, resource);
             dict = new ResourceDictionary { Source =  pack };
         }
         target.MergedDictionaries.Add(dict);
     }
 }