我正在尝试将自定义对象列表绑定到WPF图像,如下所示:
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding Path=ImagePath}" />
</Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.这是我得到的错误:
必须设置"Property'UriSource'或属性'StreamSource'."
我错过了什么?
我正在开发Windows 8应用程序.我需要知道如何以编程方式设置图像的来源.我认为Silverlight方法可行.但事实并非如此.有人知道怎么做这个吗?以下内容不起作用:
string pictureUrl = GetImageUrl();
Image image = new Image();
image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(pictureUrl, UriKind.Relative));
image.Stretch = Stretch.None;
image.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
image.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
Run Code Online (Sandbox Code Playgroud)
我得到一个异常,说:"给定的System.Uri无法转换为Windows.Foundation.Uri."
但是,我似乎无法找到Windows.Foundation.Uri类型.