XAML Image Source无法在代码中工作 [英] XAML Image Source not working in code

查看:98
本文介绍了XAML Image Source无法在代码中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从PictureLibrary获取图片的文件路径后,我想将其添加到Image控件。通常我这样做:


 BitmapImage bi =  new  BitmapImage(); 

bi.BeginInit();
bi.UriSource = new Uri("< FilePath \Filename.ext>" < /跨度>);
bi.EndInit();

Image.Source = bi;

解决方案

@Quilnux - 我实际上是在今天的演讲中介绍这个: - ) 


WinRT中没有相对URI,一切都必须是绝对的。 因此,我们扩展了URI构造函数,允许您包含基础uri。 更改为:


bi.UriSource = new Uri(this.BaseUri," FilePath / Filename.jpg");


希望这会有所帮助。


After getting the picture's file path from PictureLibrary, I wanted to add it to an Image control. Normally I do:

BitmapImage bi = new BitmapImage();

bi.BeginInit();
bi.UriSource = new Uri("<FilePath\Filename.ext>");
bi.EndInit();

Image.Source = bi;

解决方案

@Quilnux - I'm actually covering this on my talk today :-) 

There are no relative URIs in WinRT, everything must be absolute.  Because of this we've extended the URI constructor to allow you to include a base uri.  Change to:

bi.UriSource = new Uri(this.BaseUri, "FilePath/Filename.jpg");

Hope this helps.


这篇关于XAML Image Source无法在代码中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆