我有这个函数返回Uri。
public static Uri GetAppropriate(string imageName, string basePath = "/Assets/") {
switch (DisplayInformationEx.Default.FriendlyResolution) {
case FriendlyResolution.FullHD:
return new Uri("ms-appx://" + basePath + imageName + ".screen-1080p.jpg", UriKind.Absolute);
case FriendlyResolution.HD:
return new Uri("ms-appx://" + basePath + imageName + ".screen-720p.jpg", UriKind.Absolute);
case FriendlyResolution.WXGA:
return new Uri("ms-appx://" + basePath + imageName + ".screen-wxga.jpg", UriKind.Absolute);
case FriendlyResolution.WVGA:
return new Uri("ms-appx://" + basePath + imageName + ".screen-wvga.jpg", UriKind.Absolute);
default:
throw new InvalidOperationException("Unknown resolution type");
}
}
我的图像具有相对于应用程序根目录的以下路径://Assets/SquareBackground.screen-720p.jpg
当我拨打以下电话时,我看不到图像:
private ImageSource backgroundImage;
public ImageSource BackgroundImage {
get { return backgroundImage; }
set {
backgroundImage = value;
NotifyOfPropertyChange(()=>BackgroundImage);
}
}
protected override void OnViewAttached(object view, object context) {
BackgroundImage = new BitmapImage(ImageChooser.GetAppropriate("SquareBackground"));
}
我做错了什么?
答案 0 :(得分:1)
new Uri("/Assets/SquareBackground.screen-720p.jpg", UriKind.Relative);
是另一种让您使用相对于项目根目录的URI的方法