Windows-10 UWP 绑定图片 url 到 ListView 中的图片源

Windows-10 UWP Binding Image url to Image source in ListView

我正在将我的 WinRT 应用移植到 UWP。我的应用程序尝试显示图像,其 uri 是从在线查询中收到的。
我在 XAML

中像这样将它绑定到图像源
<Image  Source="{Binding ImageSrc}" Stretch="UniformToFill" />


应用程序无法从此 uri 获取图像。它只能显示应用程序容器中存在的图像(/Assets/ 文件夹中的任何内容)
我从在线查询中收到的 uri 有效。我通过在浏览器中粘贴 uri 来验证这一点。浏览器能够从 uri 获取和显示图像。

我在 Data Binding in WPF 上阅读了这个 post。它至少说,如果 "ImageSrc is a string representation of a valid uri to an image",上述绑定将起作用。 ImageSrc 在我的例子中是有效的 uri

由于上面的线程是针对 WPF 的,所以我不确定这是否适用于 UWP。在这种情况下,我还需要做些什么吗?

我可以给你一个选择。 您可以从代码隐藏文件中设置图像源。 Url 不直接使用 Image 标签的 "source" 属性 渲染。 您必须先将 URL 转换为位图图像,然后将源 属性 设置为该位图对象

试试这个,

Image.Source = new BitmapImage(
new Uri("http://yourdomain.com/image.jpg", UriKind.Absolute));

如此处问题所示 Programmatically set the Source of an Image (XAML)

如果您正在寻找基于 XAML 的绑定,方法如下:

<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding ImageSource}" />
    </Image.Source>
</Image>