Referring to image through "ms-appx:///" not working in Uri

Viewed 116

I'm currently trying to have an image source be set on Hover and I have this but it says

System.NotSupportedException: 'The URI prefix is not recognized.'

My line of code:

HoverBanner.Source = new BitmapImage(new Uri("ms-appx:///Assets/testimg.jpg"));

File Location: Image of File Location

File Properties: Image of File Properties

I've been attempting to do this for over an hour now, reading many posts, doing many methods, losing many braincells, and I'm seriously close to just giving up. Please just help me.

1 Answers

You can try to use below Uri format. Uri should start with pack.

I have used this piece of code in all over of my app to show image from resource and it's working fine.

var source = new BitmapImage();
source.BeginInit();
source.UriSource = new Uri(@"pack://application:,,,/YOUR_NAME_SPACE;component/Images/" + imgName, UriKind.Absolute);
source.EndInit();
Related