Reputation: 3442
I am trying to replace C:\Users\StrangeUser\documents\visual studio 2012\Projects\WPFGO\WPFGO\Resources\New.png
with {x:Static icons:New.png}
but it does not work New does not exists int namespace clr-namespace:WPFGO.Resources
. How to fix it?
xmlns:icons="clr-namespace:WPFGO.Resources"
<UserControl.Resources>
<Style x:Key="CreateIconButton">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<!--<Image Source="{x:Static icons:New.png}"></Image>-->
<Image Source="C:\Users\StrangeUser\documents\visual studio 2012\Projects\WPFGO\WPFGO\Resources\New.png" Height="15" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
Upvotes: 1
Views: 1292
Reputation: 11963
Add this to a top level Resource tag
<BitmapImage x:Key="somekey" UriSource="..." />
and then you will be able to do
<Image Source="{StaticResource somekey}"/>
Upvotes: 2
Reputation: 124
I ran into a similar problem like this, and wanted an easier way to manage these resources. Assuming you are going to control the file directory hierarchy from outside VS you can use the properties file to your advantage.
Now you have the ability to reference properties in your project such as this:
xmlns:prop="clr-namespace:WPFGO.Properties"
<Image Source="{Binding Source={x:Static prop:Resources.myResource}}"/>
The neat part about this would be obtaining the ability to change the location in just the resources file. XAML will build the Uri for you as well making it just a little more simple for you as the developer.
Update:
It looks like you have added the resource to VS (WPFGO\Resources\New.png) under the Resources folder. The value in the properties section might look something like this:
/Resources/New.png
Upvotes: 0