Adam Smejkal
Adam Smejkal

Reputation: 88

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?

Upvotes: 4

Views: 5202

Answers (1)

Clemens
Clemens

Reputation: 128061

Set the Image control's StretchDirection property:

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

Upvotes: 12

Related Questions