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

标签 c# windows-phone-7 windows-phone-8 windows-phone-8.1 windows-phone

我有一个属性为 BitmapImage 的模型,我正在尝试从 root -> Assets -> Icons 文件夹加载和图像并将其设置为此属性。但总是给我错误“无效的 URI:无法确定 URI 的格式。” 我们最初在 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");

关于c# - 如何从 Windows Phone 8.1 中的 Assets 文件夹中获取图像并将其分配给模型的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32336491/

相关文章:

c# - 对音频使用低通滤波器

c# - 如何使用 String.Contain 函数使用其 ascii 字符来查找字符串是否具有回车符?

c# - 从命令行构建 .xap 文件

silverlight - 在列表框上使用 VisualTreeHelper,无法获取列表框项

c# - 根级别的数据无效。第 1 行,位置 1

c# - 从我的 WP8 应用程序启动外部相机应用程序

c# - .NET 2.0 中的安全协议(protocol) Tls 1.2

c# - Fluent Api中的等价显示Annotation是什么?

xaml - Windows Phone 8 中 ListPicker 的 selectionChanged 之前的交互触发

windows-phone-8 - 限制实现的项目数或检测 LongListSelector View 中的项目