简体   繁体   English

如何从Windows Phone 8.1中的Assets文件夹中获取图像并将其分配给模型的属性

[英]How to get image from assets folder in windows phone 8.1 and assign it to a model's property

I have a model with property as BitmapImage and I am trying to load and image from root -> Assets -> Icons folder and set it to this property . 我有一个模型,其属性为BitmapImage,我试图从root-> Assets-> Icons文件夹加载图像并设置为该属性。 But always gives me the error "Invalid URI: The format of the URI could not be determined." 但是总是给我错误“无效的URI:无法确定URI的格式”。 We originally created this project in WP8.0 and then targeted it to 8.1 我们最初是在WP8.0中创建此项目,然后将其定位到8.1

                BitmapImage bi = new BitmapImage();
                bi.UriSource = new Uri(@"../Assets/Icons/noprofilepic.png", UriKind.RelativeOrAbsolute);
                bi.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                BuddyImage = bi;

Property is defined as : 属性定义为:

    private BitmapImage _BuddyImage;
    public BitmapImage BuddyImage
    {
        get { return _BuddyImage; }
        set { _BuddyImage = value; RaisePropertyChanged("BuddyImage"); }
    }

xaml control looks like below 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 = new Uri("ms-appx:///Assets/Logo.scale-240.png"); objBitmapImage.UriSource =新的Uri(“ ms-appx:///Assets/Logo.scale-240.png”);

This will work. 这将起作用。 First Check whether you are able to display images without binding.If not check the build action property of the particular image is set as "Content". 首先,检查是否能够显示没有绑定的图像。如果未选中,则将特定图像的构建操作属性设置为“内容”。

我发现以下对我来说很好用:

new Uri("Assets/Icons/noprofilepic.png", UriKind.Relative)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM