For example, in the XAML markup I use the resource from the program settings

Image Name="fon" Height="100" Width="100" Stretch="Fill" Source="pack://siteoforigin:,,,/Resources/background.jpg"/>

The fact is that it is displayed in the editor, but disappears after launch. But! If you specify a local path, then everything works. Interested in exactly how to use files from Resources

  • And if so: pack://application:,,,/Resources/background.jpg ? - VladD
  • And what does “out of settings” mean? You should have the Resources directory in the project, the background.jpg file in it, and the build action = Resource. - VladD
  • The same result (in the editor you can see, after launch it is not). I use in Visual Studio -> Project -> Properties -> Resources and I upload files there. @VladD - Vladimir H
  • Strange. And what appears in the Output? - VladD
  • @VladD If this is the "Output" in Russian, then nothing. - Vladimir H

2 answers 2

The sequence is as follows: Visual Studio -> Project -> Properties -> Resources -> Images

Add Resource -> Add Existing Object

Next, we throw on the form of Image. In the properties, select the desired image from the ones added earlier. It will be displayed on the form. However, if you run the application - nothing is visible. In the browser solution we find the Resource folder and select our image file. Next Properties -> Copy to the output directory set "Always copy."

    a little bit wrong, since the file is copied to the folder with the collected project and is referenced there (i.e. if you delete the folder located in the exe file root, the file naturally does not load or will generate an error. It is required in 1 parameter (Solution Explorer -> Image -> properties) "Action at the assembly" set to "Resource", and then in the image component in the option "source" in the drop-down list specify this added file then it will use the packed resource, in other words, we will get one exe file at the output. But it happens that "buggy", with what is connected and did not find out yl (