相关疑难解决方法(0)

图像UriSource和数据绑定

我正在尝试将自定义对象列表绑定到WPF图像,如下所示:

<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding Path=ImagePath}" />
    </Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)

但它不起作用.这是我得到的错误:

必须设置"Property'UriSource'或属性'StreamSource'."

我错过了什么?

.net data-binding wpf xaml

64
推荐指数
6
解决办法
13万
查看次数

以编程方式设置图像的来源(XAML)

我正在开发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类型.

c# xaml windows-runtime

27
推荐指数
4
解决办法
7万
查看次数

标签 统计

xaml ×2

.net ×1

c# ×1

data-binding ×1

windows-runtime ×1

wpf ×1