我有一个属性为 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/