Windows runtime 使用XAML/C中的系统文件夹路径绑定图像#
我正在用XAML/C#开发一个应用程序,其中图像的路径存储在列表中。该路径包含空格,因为它是计算机C驱动器中包含的文件的路径。我绑不住它。我试着用Windows runtime 使用XAML/C中的系统文件夹路径绑定图像#,windows-runtime,windows-store-apps,Windows Runtime,Windows Store Apps,我正在用XAML/C#开发一个应用程序,其中图像的路径存储在列表中。该路径包含空格,因为它是计算机C驱动器中包含的文件的路径。我绑不住它。我试着用 <Image Name="ImageOffer"> <Image.Source> <BitmapImage UriSource="{Binding ImagePath}" />
<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}" />
公共类视图模型
{
公共字符串ImagePath{get;set;}
公共图像源ImgSource
{
得到
{
返回新的位图图像(新的Uri(“ms appx://“+this.ImagePath));
}
}
}
请注意,要访问存储在应用程序包中的文件,请使用ms appx:scheme&
要访问存储在应用程序状态下的文件,请使用ms appdata:方案。应用程序状态可以存储在本地文件夹、漫游文件夹或临时文件夹中
更多的资源
您不能从任何位置绑定图像。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}" />
公共类视图模型
{
公共字符串ImagePath{get;set;}
公共图像源ImgSource
{
得到
{
返回新的位图图像(新的Uri(“ms appx://“+this.ImagePath));
}
}
}
请注意,要访问存储在应用程序包中的文件,请使用ms appx:scheme&
要访问存储在应用程序状态下的文件,请使用ms appdata:方案。应用程序状态可以存储在本地文件夹、漫游文件夹或临时文件夹中
更多的资源
但我的要求是以这种方式绑定图像:(但我的要求是以这种方式绑定图像:(