My WPF application has several windows and I want to use the same background image for all of them. I've defined the bitmap and image brush in a resource dictionary as follows.
<BitmapImage x:Key="BackgroundImage" UriSource="/Resources/BackPlate.png"/>
<ImageBrush x:Key="BackgroundBrush" ImageSource="{StaticResource BackgroundImage}" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,128,128"/>
When I set the background property in the Window description, the background changes successfully in Visual Studio, but when I run the application, I get a parsing exception, I assume because the window resources haven't actually been read yet?
<Window x:Class="MyApp.Test"
...
Background="{StaticResource BackgroundBrush}">
<Window.Resources>
...
Is there another way to specify the background after the resources have been read? I've tried the Window.Background approach, but I can't figure out how to get it to work w/o specifying the whole image brush definition.
<Window.Background>
<ImageBrush ?>
</Window.Background>
Is there a way to specify the image brush by reference when using this approach?