/// <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); } }
/// <summary> /// Load a theme from a Stream. /// </summary> /// <param name="stream">A Stream containing the theme to load.</param> /// <param name="owner">ResourceDictionary owner.</param> /// <returns>ResourceDictionary corresponding to the loaded theme.</returns> private static ResourceDictionary LoadThemeResources(Stream stream, ResourceDictionary owner) { // Load the theme ResourceDictionary resources = null; using (stream) { resources = ResourceParser.Parse(stream, true); owner.MergedDictionaries.Add(resources); } return(resources); }
/// <summary> /// Retrieves a style collection from a uri of a resource /// dictionary. /// </summary> /// <param name="uri">The uri of a resource dictionary.</param> /// <returns>A style collection containing the styles in the resource /// dictionary.</returns> private static ResourceDictionary Parse(Uri uri) { Debug.Assert(uri != null, "uri cannot be null."); StreamResourceInfo info = Application.GetResourceStream(uri); if (info == null) { throw new ResourceNotFoundException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ImplicitStyleManager_ResourceNotFound, uri)); } else { try { return(ResourceParser.Parse(info.Stream, true)); } catch (Exception exception) { throw new InvalidResourceException(Properties.Resources.InvalidResourceException_UnableToLoadResources, exception); } } }