我正在用XAML/c#开发一个应用程序,其中图像的路径存储在列表中。该路径包含空格,因为它是计算机C驱动器中文件的路径。我无法捆绑它。我试着用
<Image Name="ImageOffer">
<Image.Source>
<BitmapImage UriSource="{Binding ImagePath}" />
</Image.Source>
</Image>
谁能告诉我在XAML中如何从应用程序的外部文件夹绑定图像?由于
您不能从任何位置绑定图像。WinRT有沙盒环境,所以你只能从已知的位置绑定图像,比如库,本地文件夹,资源文件夹。
public class ViewModel
{
public string ImagePath { get; set; }
public ImageSource ImgSource
{
get
{
return new BitmapImage(new Uri("ms-appx:///" + this.ImagePath));
}
}
}
<Image Source="{Binding ImgSource}" />
请注意访问存储在应用程序包中的文件使用ms-appx: scheme &要访问存储在应用程序状态下的文件,请使用ms-appdata:方案。应用程序状态可以存储在本地文件夹、漫游文件夹或临时文件夹中。
更多资源
如何加载文件资源(Windows Store应用程序使用c#/VB/c++和XAML)
处理本地文件系统图像的WinRT图像控件和ViewModel之间的绑定