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

后端 未结 7 2048
隐瞒了意图╮
隐瞒了意图╮ 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:19

    You will need to use the page's BaseUri property or the image control's BaseUri property like this:

    //using the page's BaseUri property
    BitmapImage bitmapImage = new BitmapImage(this.BaseUri,"/Images/800x600/BackgroundTile.bmp");
    image.Source = bitmapImage;
    

    or

    //using the image control's BaseUri property
    image.Source = new BitmapImage(image.BaseUri,"/Images/800x600/BackgroundTile.bmp");
    

    you can see the reason and solution here

提交回复
热议问题