0

I don't understand why this code doesn't work

<Image Source="pack://application:,,,/Resources/Steam.png" Width="30"/>

https://stackoverflow.com/questions/62032643/using-image-in-xaml-from-resources-resx

how should I use embedded resource? I just don't want all the resources to be in the bin folder can someone help me on how to use EmbeddedResource in Xaml?

<Image Source="pack://application:,,,/Resources/Steam.png" Width="30"/>
<Image Source="/Resources/Steam.png" Width="30"/>
  <ItemGroup>
    <EmbeddedResource Include="Resources\Steam.png" />
  </ItemGroup>

I tried many options but didn't work for me

1

2 Answers 2

0

I found an answer for you, although it is not in xaml. I've done a lot of research and couldn't find a xaml method, but it still is possible to keep the image as an embedded resource, without having it in your root app directory. You need to first put your images in a directory you can result to. and have the images set to "Embedded Resource" not "Resource" or anything else. In C# The code looks like this

Stream streamVar = this.GetType().Assembly.GetManifestResourceStream("YourProjectNameHere.TheDirectory(FormattedInPeriodsInsteadOfSlahses).YourImageHere.ImageExtensionType");
BitmapImage bitmapimageVar = new();
bitmapimageVar.SetSource(streamVar.AsRandomAccessStream());
YourXAMLUIImageElement.Source = sampleBitmapImageVariable;

Here is my Sample of code and directories

Stream s = this.GetType().Assembly.GetManifestResourceStream("Hostware.Icons.appicon.png");
BitmapImage img = new();
img.SetSource(s.AsRandomAccessStream());
appicon_image.Source = img;

Hope this helps! I spent too long trying to find an xaml method, if you have found a solution in xaml already, please let me know, because I want it

Sign up to request clarification or add additional context in comments.

Comments

0

Should it not be like this?
At least, that's what I'm using.

<Image Source="ms-appx:///Resources/Steam.png" Width="30"/>

1 Comment

I just realized this uri-scheme is for content files (in packaged applications). My bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.