图像在 Win8/Win10 但不是 Win7 中呈现

Image Renders in Win8/Win10 but not Win7

我的文档中有以下 XAML:

<Border HorizontalAlignment="Right" VerticalAlignment="Bottom"
        Height="100" Width="100"
        BorderBrush="Red" BorderThickness="2">
    <Image x:Name="image"
           Source="http://myinternalserver/mywebservice/getimage.aspx?id=1234&amp;ContentType=Image" />
</Border>

图像在 Win10 和 Win8 中显示正常,但在 Win7 中我得到的只是一个带有透明背景的红色边框,里面没有图像。当我使用静态 URL 时,例如 google 徽标,它会在所有版本中呈现。

有人知道我如何在 Windows 7 中渲染图像吗?

尝试通过从代码隐藏文件订阅 Image.ImageFailed 事件来检查可能的异常:

public MainWindow()
{
    InitializeComponent();
    image.ImageFailed += ImageFailed;
}

private void ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
    Console.WriteLine(e.ErrorException);
}

根据 this post 不能将 WebUrl 指定为 BitmapImage 的源。我建议你制作一个助手 class 而不是在视图的代码隐藏中这样做。此外,我会冻结创建的图像以提高性能。