I'm having a little issue here in showing images.
So when I'm trying to load images from XAML, I can use a relative uri to the image source like this :
<Image Source="/Assets/image.jpg" />
But if I try to change the image source programatically from code behind, I always get an exception and I'm sure it's because of the false Uri. I tried something like this :
BitmapImage bitmapImage = new BitmapImage(new Uri("/Assets/image.jpg"));
Am I doing it wrong? Any help will be appreciated, thanks!
Here's how to set the source to an image from the app package. Image img = new Image(); BitmapImage bitmapImage = new BitmapImage(); Uri uri = new Uri("ms-appx:///Assets/Logo.png"); bitmapImage. UriSource = uri; img. Source = bitmapImage; // OR Image img = new Image(); img.
Go to tool box and drag and drop the image into the designer page. In the solution explorer go to assets and right click. Then click add -> existing item. Browse the required file.
You can also use it with BaseUri.
BitmapImage bitmapImage = new BitmapImage(new Uri(this.BaseUri, "/Assets/image.jpg"));
Assets is a folder name and you can change it with your any custom folder name :)
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