Search code examples
wpfimagecropstretch

WPF - Don't stretch image but fit it in a container (or MaxHeight)


I would like to display an image in WPF in its original size, which can be achieved by setting Stretch="None". However, if the image is bigger than its enclosing element, the image gets cropped, which is undesirable.

I would like the image to be downsized if it doesn't fit, but not stretched when it is smaller than its enclosing element. Is there a way to achieve this behaviour?


Solution

  • Set the Image control's StretchDirection property:

    <Image Stretch="Uniform" StretchDirection="DownOnly" ... />