C# 如何从windows phone 8.1中的资产文件夹中获取图像并将其分配给型号';s属性
我有一个属性为BitmapImage的模型,我正在尝试从root->Assets->Icons文件夹加载和镜像,并将其设置为此属性。但是总是给我一个错误“无效的URI:无法确定URI的格式” 我们最初在WP8.0中创建了这个项目,然后将其定位于WP8.1C# 如何从windows phone 8.1中的资产文件夹中获取图像并将其分配给型号';s属性,c#,windows-phone-7,windows-phone-8,windows-phone-8.1,windows-phone,C#,Windows Phone 7,Windows Phone 8,Windows Phone 8.1,Windows Phone,我有一个属性为BitmapImage的模型,我正在尝试从root->Assets->Icons文件夹加载和镜像,并将其设置为此属性。但是总是给我一个错误“无效的URI:无法确定URI的格式” 我们最初在WP8.0中创建了这个项目,然后将其定位于WP8.1 BitmapImage bi = new BitmapImage(); bi.UriSource = new Uri(@"../Assets/Icons/noprofilepic.
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");
使用ms appx:///例如:
bi.UriSource = new Uri("ms-appx:///Assets/Icons/noprofilepic.png");
objBitmapImage.UriSource=新Uri(“ms-appx:///Assets/Logo.scale-240.png");
这会奏效的。首先检查是否能够在不绑定的情况下显示图像。如果不能,请检查特定图像的生成操作属性是否设置为“内容”。objBitmapImage.UriSource=new Uri(“ms-appx:///Assets/Logo.scale-240.png");
这会奏效的。首先检查您是否能够在不绑定的情况下显示图像。如果不检查,则将特定图像的生成操作属性设置为“内容”。我发现以下方法对我很有效:
new Uri("Assets/Icons/noprofilepic.png", UriKind.Relative)
我发现以下几点对我很有效:
new Uri("Assets/Icons/noprofilepic.png", UriKind.Relative)
是的,它给出了无效的uri错误。奇怪的是,另一个地方,如果我使用任何一个,您提供的上述解决方案都会起作用..不确定为什么我不能在viewmodel classpublic BitmapImage BuddyImage{get{BitmapImage bi=new BitmapImage();bi.UriSource=new Uri(“ms”)中这样做-appx:///Assets/Icons/noprofilepic.png");return bi;}}}将其添加到视图模型中是的,它给出了无效的uri错误。奇怪的是,另一个地方,如果我使用任何一个,您提供的上述解决方案都会起作用..不确定为什么我不能在viewmodel classpublic BitmapImage BuddyImage{get{BitmapImage bi=new BitmapImage();bi.UriSource=new Uri(“ms”)中这样做-appx:///Assets/Icons/noprofilepic.png");return bi;}}将其添加到视图模型中