的 SourceImage绑定到指向图像的 URL。
如果 URL 上的图像小于MaxHeightand MaxWidth,则以下代码效果很好。图像大小与 url 完全相同,并且窗口大小正确。
如果 URL 上的图像大于MaxHeight和MaxWidth,则仅显示图像的一部分。图像不会缩小以适合窗口。
如果我删除Stretch="None",然后大图片会缩小以适合MaxHeightand MaxWidth,看起来很棒,但小图片会扩大以消耗所有可用空间,看起来像废话。
这是我一直在测试的两张图片:
http://imgur.com/iaBp2Fv,fiRrTJS#0
<Window x:Class="MyNamespace.Windows.PictureWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Profile Picture" ResizeMode="NoResize" UseLayoutRounding="True" SizeToContent="WidthAndHeight" MaxHeight="750" MaxWidth="750">
<Image Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding}" />
</Window>