如何从 windows phone 8.1 中的资产文件夹中获取图像并将其分配给模型的 属性
How to get image from assets folder in windows phone 8.1 and assign it to a model's property
我有一个 属性 作为 BitmapImage 的模型,我正在尝试从 root -> Assets -> Icons 文件夹加载图像并将其设置为此 属性 。但总是给我错误 "Invalid URI: The format of the URI could not be determined."
我们最初在WP8.0中创建了这个项目,然后将其定位到8.1
BitmapImage bi = new BitmapImage();
bi.UriSource = new Uri(@"../Assets/Icons/noprofilepic.png", UriKind.RelativeOrAbsolute);
bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
BuddyImage = bi;
属性 定义为:
private BitmapImage _BuddyImage;
public BitmapImage BuddyImage
{
get { return _BuddyImage; }
set { _BuddyImage = value; RaisePropertyChanged("BuddyImage"); }
}
xaml 控件如下所示
<Image Source="{Binding BuddyImage}" Width="75" Height="75" Stretch="Uniform"/>
使用 ms-appx:/// 例如:
bi.UriSource = new Uri("ms-appx:///Assets/Icons/noprofilepic.png");
objBitmapImage.UriSource = 新 Uri("ms-appx:///Assets/Logo.scale-240.png");
这会奏效。首先检查您是否能够在没有 binding.If 的情况下显示图像,而不是检查特定图像的构建操作 属性 是否设置为 "Content"。
我发现以下方法对我来说效果很好:
new Uri("Assets/Icons/noprofilepic.png", UriKind.Relative)
我有一个 属性 作为 BitmapImage 的模型,我正在尝试从 root -> Assets -> Icons 文件夹加载图像并将其设置为此 属性 。但总是给我错误 "Invalid URI: The format of the URI could not be determined." 我们最初在WP8.0中创建了这个项目,然后将其定位到8.1
BitmapImage bi = new BitmapImage();
bi.UriSource = new Uri(@"../Assets/Icons/noprofilepic.png", UriKind.RelativeOrAbsolute);
bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
BuddyImage = bi;
属性 定义为:
private BitmapImage _BuddyImage;
public BitmapImage BuddyImage
{
get { return _BuddyImage; }
set { _BuddyImage = value; RaisePropertyChanged("BuddyImage"); }
}
xaml 控件如下所示
<Image Source="{Binding BuddyImage}" Width="75" Height="75" Stretch="Uniform"/>
使用 ms-appx:/// 例如:
bi.UriSource = new Uri("ms-appx:///Assets/Icons/noprofilepic.png");
objBitmapImage.UriSource = 新 Uri("ms-appx:///Assets/Logo.scale-240.png");
这会奏效。首先检查您是否能够在没有 binding.If 的情况下显示图像,而不是检查特定图像的构建操作 属性 是否设置为 "Content"。
我发现以下方法对我来说效果很好:
new Uri("Assets/Icons/noprofilepic.png", UriKind.Relative)