/// <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; dict = new ResourceDictionary { Source = RuntimeHelper.MakePackUri(sourceAssembly, resource) }; } target.MergedDictionaries.Add(dict); } }
/// <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()); } }
/// <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()); } }
/// <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); } }