WPF Get image from RESX file

In WPF XAML, I have an image tag, and I'm trying to set the image source to a resx file. Fou.png is configured to create an embedded resource action. For the life of me, I can’t fix the source text, it says that Fou.png is not part of the project, although I see it in the file Resouces foulder / Resx. I tried these below to no avail

Ideas

+4
source share
4 answers

Build action should be a Resource, not a Nested Resource

+1
source

The 1st of all "Embedded Resource" is not recommended in WPF (don’t remember why, but if you find it, you will find an explanation)

Resource loading method:

a) In Visual studio, add the "Resources" folder to the project and add your images to it.

b) Then in XAML you can access them as follows:

<Image Width="18" Source="/MyApplication;component/Resources/Foo.png" /> 

In this example, “MyApplication” is the name of the assembly (see the first line of your XAMl x: Class = to get the name of your assembly) “Resources” is the name of the folder containing the resources, and “Foo. Png” is the name of the image.

Good luck.

Jm

+1
source

Make sure you set the width and height properties of your Image control. At least in the simplest test project, the image is not displayed if the width and height are not specified.

0
source
 <Image x:Name="myImage" Source="..\Resources\icon.jpg"></Image> 

Properties: Set the "Create" action to "Resource" instead of "Embedded resource"

In the test test project that I created, I had an image file named icon.jpg added to a Resouce file called MyResource.resx. XAML image width and height are optional

-2
source

Source: https://habr.com/ru/post/1345362/


All Articles