Question

I've separated all my images into a Resource Dictionary and assigned them in the XAML as static resources and this works fine at design time.

When I come to run my application, all my images and form background (I've used an image brush for the Window background) are black?

I've set the Build Action of the RD to Resource and Copy Always.

I've copied my resources into a subfolder of my output folder but still no success.

What am I doing wrong?

Thanks

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<SolidColorBrush x:Key="StandardSolidColorBrush" Color="Blue" />
<LinearGradientBrush x:Key="StandardLinearGradientBrush" StartPoint="0.0,0.0" EndPoint="1.0,1.0">
    <LinearGradientBrush.GradientStops>
        <GradientStop Color="White" Offset="0" />
        <GradientStop Color="Black" Offset="1" />
    </LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="TextBlock_Underlined">
      <Setter Property="TextBlock.TextDecorations" Value="Underline" />
</Style>

<BitmapImage x:Key="UpArrow" UriSource="./Resources/Images/upload_orange.png" />
<BitmapImage x:Key="MainBackground" UriSource="./Resources/Images/background.jpg" />

Was it helpful?

Solution

In the properties for the image resource:

Build Action: Content

Copy to Output Directory: Copy Always (or copy if newer)

The image will now be available in design time and run time.

You may be able to use Build Action of Resource, but will need to declare the image's Source a bit differently. Here's a decent article on Working with Images: Content vs Resource build action

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top