Reputation: 4655
I have an image file that is rectangular, say 300px by 200px
I would like to display it in an Image control that is 100px by 100px.
How can I say to the Image control to display the image like this
instead of like this?
(In red is my Image control and in black is my image file)
Upvotes: 1
Views: 580
Reputation: 128013
In order to create a centered image, you may set UniformToFill
on an ImageBrush
:
<Rectangle Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center">
<Rectangle.Fill>
<ImageBrush ImageSource="..." Stretch="UniformToFill"/>
</Rectangle.Fill>
</Rectangle>
Upvotes: 3
Reputation: 1854
In your image code, in xaml, add this property:
Stretch="UniformToFill"
It will adjust image to fill all of the square without changing his proportion.
Upvotes: 1