如何强制图像在 WPF 中保持纵横比?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15906117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I force an image to maintain aspect ratio in WPF?
提问by DaveDev
I have an image in a WPF window. When I resize the window the image resizes with it. Is it possible to preserve the aspect ratio when the image is resizing, so it doesn't look squashed if the window is too narrow? If so, how?
我在 WPF 窗口中有一个图像。当我调整窗口大小时,图像也会随之调整大小。是否可以在调整图像大小时保持纵横比,因此如果窗口太窄,它看起来不会被压扁?如果是这样,如何?
回答by Federico Berasategui
Set the Image.StretchProperty to Uniform
将Image.Stretch属性设置为Uniform
<Image Stretch="Uniform" ....etc />

