Stretch image to fill available width / height (separately)

c#, image, wpf

Solution

I think that you might be able to get the effect you desire in certain conditions. If your images are all bigger than the size that they will be displayed, you could possibly use this:

<Image Source="Desert.jpg" Stretch="UniformToFill" StretchDirection="DownOnly" />

A `ViewBox` has the same `Stretch` properties as an `Image` and there is a good example of the differences between the different combinations in the How to: Apply Stretch Properties to the Contents of a Viewbox article on MSDN.

Problem

Is it any way to fill available width / height with image in xaml? I need something like UniformToFill, but where I can control stretch direction (width or height) Assume I have have following code: ``` <UniformGrid Columns="2" Rows="2"> <Image Source="Desert1.jpg" Stretch="Uniform"/> // <Image Source="Desert2.jpg" Stretch="UniformToFill"/> // <Image Source="Desert3.jpg" /> <Image Source="Desert4.jpg" /> </UniformGrid> ``` EDIT: for examle (width): if image is half as wide as I want to show, I don't care about height and just scale x2 image height and width. So image must fit width, and don't care about height. It's desired behaviour, but if it's not possible - ok. So you can rethink question as IF it possible, HOW can I do it in xaml. Also all images may have different width and height

Original source