0

I'm trying to get an image of my project and put it in a Style of my App.xaml

<Style x:Key="image_campange_map" TargetType="Image">
    <Setter Property="Source" Value="../Images/map.jpg"/>
</Style>

The problem : Could not find a part of the path 'C:\WINDOWS\Images\map.jpg

How could i get the local path of the Image i'm stylling ? Thanks !

omega478
  • 7
  • 4

1 Answers1

2

Set the Build Action to "Content" and the Output to "Copy Always" in the Images properties.

Then create a BitmapImage resource instead of a style. Example:

 <Window.Resources>
    <BitmapImage x:Key="myKey" UriSource="Images/map.jpg"/>
 </Window.Resources>

Now just set your Image source

 <Image Source="{StaticResource myKey}"/>
Tronald
  • 1,520
  • 1
  • 13
  • 31
  • Thank for this answer but could you give me an exemple please ^^ ? I don't understand where i have to add this. – omega478 Apr 21 '18 at 20:00
  • It's okay, i finally understand what was image properties ^^ Right Click on the Image -> Properties But it doesn't work anyway :/ – omega478 Apr 21 '18 at 20:37
  • @omega478 i just remembered setting relative path in style doesn't work right. I edited my answer.Honestly though, I feel like it's easier to just set the Image Source directly. Not sure why you need a style though. – Tronald Apr 21 '18 at 22:06
  • Okay @Tronald Thx a lot for your time ! – omega478 Apr 21 '18 at 22:50
  • Better than Content and Copy Always would be to set the Build Action to Resource. – Clemens Apr 22 '18 at 18:28