/// <summary> /// ResourceDictionaryUriProperty property changed handler. /// </summary> /// <param name="dependencyObject">FrameworkElement that changed its /// ResourceDictionaryUri.</param> /// <param name="eventArgs">Event arguments.</param> private static void OnResourceDictionaryUriPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs) { FrameworkElement element = dependencyObject as FrameworkElement; if (element != null) { Uri value = (Uri)eventArgs.NewValue; ResourceDictionary resourceDictionary = null; if (value != null) { try { resourceDictionary = Parse(value); ImplicitStyleManager.SetExternalResourceDictionary(element, resourceDictionary); } catch (Exception) { element.ClearValue(ImplicitStyleManager.ExternalResourceDictionaryProperty); throw; } } else { element.ClearValue(ImplicitStyleManager.ExternalResourceDictionaryProperty); } } }
/// <summary> /// Load a theme from a resource stream. /// </summary> /// <param name="themeResourceStream"> /// A resource stream containing the theme to load. /// </param> private void LoadTheme(Stream themeResourceStream) { Debug.Assert(themeResourceStream != null, "themeResourceStream should not be null!"); // Load the theme using (Stream stream = themeResourceStream) { ResourceDictionary resources = ResourceParser.Parse(stream, true); ImplicitStyleManager.SetExternalResourceDictionary(this, resources); } }