Image 来自磁盘Xamarin窗体的图像源
我有一个Xamarin Forms应用程序,我想做的是将图像视图的源设置为UWP中磁盘中的特定图像。 也就是说,我拥有磁盘中映像的绝对路径,并且我希望以编程方式设置映像视图的源。 我试过使用Image 来自磁盘Xamarin窗体的图像源,image,file,xamarin,uwp,Image,File,Xamarin,Uwp,我有一个Xamarin Forms应用程序,我想做的是将图像视图的源设置为UWP中磁盘中的特定图像。 也就是说,我拥有磁盘中映像的绝对路径,并且我希望以编程方式设置映像视图的源。 我试过使用 image.Source = ImageSource.FromFile(filePath); 但是它在UWP中不起作用,尽管它在Android中起作用。一个好的方法是在您的视图模型中使用一种基于操作系统放置路径的方法 查看 <Image Source="{Binding ImagePath}" /&
image.Source = ImageSource.FromFile(filePath);
但是它在UWP中不起作用,尽管它在Android中起作用。一个好的方法是在您的
视图模型中使用一种基于操作系统放置路径的方法
查看
<Image Source="{Binding ImagePath}" />
为图像设置路径时,可以使用如下函数:
public static class OSHelpers {
/// <summary>
/// Sets the os image path.
/// </summary>
/// <param name="ImageName">Name of the image.</param>
/// <returns>System.String.</returns>
public static string SetOSImagePath(string ImageName) {
string rtn = ImageName;
if (Device.OS == TargetPlatform.Windows || Device.OS == TargetPlatform.WinPhone) {
rtn = "Images/" + ImageName;
}
return rtn;
}
}
公共静态类OSHelpers{
///
///设置操作系统映像路径。
///
///图像的名称。
///System.String。
公共静态字符串SetOSImagePath(字符串ImageName){
字符串rtn=图像名称;
if(Device.OS==TargetPlatform.Windows | | Device.OS==TargetPlatform.WinPhone){
rtn=“Images/”+ImageName;
}
返回rtn;
}
}
可能重复的问题不是重复的问题
public static class OSHelpers {
/// <summary>
/// Sets the os image path.
/// </summary>
/// <param name="ImageName">Name of the image.</param>
/// <returns>System.String.</returns>
public static string SetOSImagePath(string ImageName) {
string rtn = ImageName;
if (Device.OS == TargetPlatform.Windows || Device.OS == TargetPlatform.WinPhone) {
rtn = "Images/" + ImageName;
}
return rtn;
}
}