I have a Universal Windows application that hosts a main menu. I want a plugin architecture, where the menu items are added from class libraries.
But I can't seem to load images correctly. I can't get the ms-appx:///
working, and when I try to add the images as an embedded resource, it hangs:
var assembly = typeof(CookModule).GetTypeInfo().Assembly;
using (var imageStream = assembly.GetManifestResourceStream("My.Namespace.Folder.ImageName-100.png"))
using (var raStream = imageStream.AsRandomAccessStream())
{
var bitmap = new BitmapImage();
bitmap.SetSource(raStream); //<- Hangs here
I get no exceptions, errors in the output or anything. It just hangs there, and the app simply doesn't load the page.
I have also tried:
var bitmap = new BitmapImage(new Uri("/Folder/ImageName-100.png"));
I'm missing something similar to the WPF pack uri's where I can state which assembly to load the image from.
What is the correct (and working) way of adding a image resource to a Page from a class libary? (Or does anyone have a working example of ms-appx where the image is in a class library)
I can reproduce this issue. Current workaround I used is copying the resource stream to .NET memory stream.
var assembly = typeof(CookModule).GetTypeInfo().Assembly;
using (var imageStream = assembly.GetManifestResourceStream("UWP.ClassLibrary.210644575939381015.jpg"))
using (var memStream = new MemoryStream())
{
await imageStream.CopyToAsync(memStream);
memStream.Position = 0;
using (var raStream = memStream.AsRandomAccessStream())
{
var bitmap = new BitmapImage();
bitmap.SetSource(raStream);
display.Source = bitmap;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With