0

I'm pretty new to coding and I am currently using a background image for a WPF application that I am building. Right now I have it working like this:

this.Background = new ImageBrush(new BitmapImage(new Uri("Background 1.jpg", UriKind.Relative)));

But this would require copying the image over to the final file when I go to publish this. Is there some way that I can embed this image in the visual studio solution so that I don't have to copy it? Or am I just stuck copying it over every time? Also, if I can embed an image into the file, how do I call it? I assume I wouldn't use UrlKind.Relative and the location like I am now because it wouldn't be right in the directory. I'd be ok doing this in XAML too if there's an easier way, I just am kind of new to all this.

Thanks!

Blake
  • 109
  • 3
  • 7

1 Answers1

0

You can embed the image in your project and set it's build action to resource.

Then you can access it by

Uri uri = new Uri("pack://application:,,,/Background 1.jpg");
BitmapImage bitmapImage = new BitmapImage(uri);
Raj Ranjhan
  • 3,869
  • 2
  • 19
  • 29