Reputation: 508
I'm working on a windows universal app. I want to show the user an image. The image is located in a subfolder within my assets folder, in both the phone and the windows folder.
I'm trying to put the image in a variable in a class that is in the shared folder. I am continously getting uri exceptions.
My code looks like this:
Uri uri = new Uri("/Assets/Image/avatar_anonymous.png");
chat_profilepicture_Bitmap = new BitmapImage(uri);
I've tried different urls, with and without capitals, the entire path "C://blablabla", and many more. Nothing seems to be working. I have also tried: pack://application:,,,/ which was suggested by multiple stackoverflow threads. But no luck there.
I'm thinking the problem lies in the image being in another project, is there a way to get around this? Or if this isn't the problem, what am I doing wrong?
Upvotes: 1
Views: 785
Reputation: 8231
In Windows Universal App, You can use Image Resource with ms-appx or ms-appdata.
So the uri can be written like this:
new Uri("ms-appx:///Assets/Image/avatar_anonymous.png", UriKind.Absolute);
or
new Uri("ms-appdata:///LocalFolderName/demo.png", UriKind.Absolute);
Upvotes: 3
Reputation: 4292
Try this
Uri uri = new Uri("ms-appx:///Assets/Image/avatar_anonymous.png");
Hope this helps
Upvotes: 5