给定的 System.Uri 无法转换为 Windows.Foundation.Uri

给定的 System.Uri 无法转换为 Windows.Foundation.Uri

问题描述:

我正在尝试以编程方式在 XAML Metro 应用程序中加载 BitmapImage.这是我的代码:

I'm trying to programmatically load a BitmapImage in a XAML Metro app. Here's my code:

var uri = new Uri("/Images/800x600/BackgroundTile.bmp", UriKind.RelativeOrAbsolute);
var imageSource = new BitmapImage(uri);

第二行因 System.ArgumentException 崩溃:

The second line crashes with a System.ArgumentException:

给定的 System.Uri 无法转换为 Windows.Foundation.Uri.请参阅http://go.microsoft.com/fwlink/?LinkID=215849了解详情.>

The given System.Uri cannot be converted into a Windows.Foundation.Uri. Please see http://go.microsoft.com/fwlink/?LinkID=215849 for details.

链接只是转到 MSDN 主页,所以没有用.

The link just goes to the MSDN home page, so it's no use.

我还尝试删除前导 /,以防 WinRT 对相对 URI 有不同的期望,但我仍然遇到相同的异常.

I've also tried removing the leading /, in case WinRT has different expectations about relative URIs, but I still get the same exception.

为什么我会收到这个看似完全有效的 URI 的异常?

Why am I getting this exception for what seems to be a perfectly valid URI?

在 Consumer Preview 中,正确的 URL 格式显然已更改为 ms-appx:/Images/800x600/BackgroundTile.bmp

In the Consumer Preview, the correct URL format has apparently changed to ms-appx:/Images/800x600/BackgroundTile.bmp