0

First I would like to mention that I am a very beginner in UI design. This is actually my first time trying to design an App.

I have inserted an image on my MainWindow application but this image does not show up after the build.

I have tried everything that I found on StackOverflow, but nothing seems to work for me. What I would like to accomplish is: have a single location where I can store the metadata of my image and call the key every time I want to use it.

The first thing that I tried was just to insert the image in my xaml code. For that purpose, I created a folder in my project called Resources and I included my image Info.png. Then I simply inserted the image in my XAML code in a stackpanel. The image appears in the design but not after the build.

<StackPanel Margin="435 297 55 50">
   <Image Source="Resources/Info.png"/>                    
</StackPanel> 

Then, after reading a lot on Stack and watching videos on Youtube, I changed the properties of the image. Set Build Action to Ressources and Copy to Output Directory to Copy If Newer. The Image still was not appearing. Applied what I saw here and here, still no show.

I then saw a Youtube Video explaing that I should put my image in my App.xaml so that I can reference it using the key. I did this:

<Application.Resources>
   <ResourceDictionary>
      <BitmapImage x:Key="Info" UriSource="Resources/Info.png"/>
   </ResourceDictionary>
</Application.Resources>

Then in my MainWindow.xaml, I change the image code like this:

<StackPanel Margin="435 297 55 50">
   <Image Source="{StaticResource Info}"/>                    
</StackPanel>

This was giving me an error saying the resource 'Info' could not be found, even thought I could see the image in the design. So I changed it like this:

<StackPanel Margin="435 297 55 50">
   <Image Source="{StaticResource ResourceKey=Info}"/>                    
</StackPanel>

But this was still rendering the same error. Then somehow, I ended up with this

<StackPanel Margin="435 297 55 50">
   <Image Source="{DynamicResource Info}"/>                    
</StackPanel>

This was not rendering an error but now I couldn't see the image neither on the design nor after the build.

I think the idea of putting the image in the App.xaml so that I can reference it by the key is a good idea but it just doesn't seem to work. Can you please help me solve this issue. I am using VS 2019

Community
  • 1
  • 1
  • Check your picture properties. You want build resource, do not copy. This compiles it into the exe. It's in the resources folder? – Andy Nov 16 '19 at 00:02
  • Hi Andy. The image is indeed in the resources folder. I have tried to set the property to 'Do not Copy' but this does not work neither – Bruno Bukavu Thai Nov 16 '19 at 00:20

0 Answers0