UWP - Image Uri in Application Folder

前端 未结 5 1340
自闭症患者
自闭症患者 2020-12-10 10:51

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 :

<         


        
5条回答
  •  悲哀的现实
    2020-12-10 11:32

    To access files stored inside the application package, but from code where there is no inferred root authority, you need to specify the ms-appx: scheme :

    So in your case it will be something like :

    BitmapImage bitmapImage = 
                         new BitmapImage(new Uri("ms-appx:///[project-name]/Assets/image.jpg"));
    

    Read this documentation for more details : https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh965322.aspx

    Hope it helps.

提交回复
热议问题