Image control in WPF

The image control is used to display various formats of images in WPF applications. The basic steps include adding the image control to the window/page and setting its source property. To adjust the dimensions of the image we can set the stretch and stretchdirection properties.

Stretch can be set to the following properties:
None – The picture is not stretched. It is displayed at its original size.
Fill – The picture is stretched to fill the Image control.
Uniform – The picture is uniformly stretched vertically and horizontally to fill the Image control.
UniformToFill – The picture is stretched by the same amount vertically and horizontally
until it completely flls the Image control. If the picture doesn’t have the same width-to-height
ratio as the Image control, then some of the picture will stick out past the edges of the control and will be clipped.

The StretchDirection determines which way the image could be stretched to fit the image control while using the stretch property. It takes the following values

UpOnly – The picture can only be stretched to make it larger.
DownOnly – The picture can only be shrunk to make it smaller.
Both – The picture can be stretched or shrunk.

<Image Width=”Auto” Height=”Auto”
 HorizontalAlignment=”Stretch” VerticalAlignment=”Stretch”
 Source=”myimage.jpg” Stretch=”UniformToFill” />

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.