0

I have a WPF application structured according the MVVM pattern. I wish to set the application background image at runtime, loading a file stored in MyProjectView/images/background.jpg. So, in MyProjectViewModel layer I wrote a procedure to load the background image

        Public Sub LoadBackground()
        Dim fs As New FileStream("images/background.jpg", FileMode.Open, FileAccess.Read)

        img = New Byte(fs.Length - 1) {}
        fs.Read(img, 0, System.Convert.ToInt32(fs.Length))
        End Sub

This code work only in the Debug mode. When I deploy my application, no background is loaded, because the image file is not loaded into the deployed folder "images". I tried to set the "Action" property of the file to "EmbeddedResource", but nothing happens. how can I do to add the background.jpg file into my deployment package?

calacausi
  • 23
  • 5
  • http://stackoverflow.com/questions/90697/how-to-create-and-use-resources-in-net –  Jan 20 '17 at 15:11

1 Answers1

0

Set the Build Action to Content and the Copy to Output Directory property to Copy if newer.

This will copy both the "images" folder and the file to the output folder of the .exe when you build the application.

mm8
  • 163,881
  • 10
  • 57
  • 88