The given System.Uri cannot be converted into a Windows.Foundation.Uri

后端 未结 7 2038
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 10:47

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.Re         


        
7条回答
  •  粉色の甜心
    2020-12-01 11:06

    Judging from the documentation for Windows.Foundation.Uri, it looks like WinRT doesn't support relative URIs. I tried a pack:// URI, but that gave me a UriFormatException, so apparently that's not the way to do it in WinRT either.

    I found the answer on this thread: MS invented yet another URI format for WinRT resources. This works:

    new Uri("ms-resource://MyAssembly/Images/800x600/BackgroundTile.bmp")
    

    Note that you don't add your actual assembly name -- the MyAssembly part is literal text.

提交回复
热议问题