tags:

views:

28

answers:

1

I have a grid with an image in it. Initially, the image is larger than the grid, so it gets cropped which is fine, but if I apply a scaling transform to causing the image to shrink, the portion that was initally cropped remains cropped, but I want it displayed now, because it would fit in the grid.

I concidered putting my image in a canvas, but I want it centered vertically and horizontally, which is giving me trouble, so I switched to a grid.

A: 

Setting the Stretch property will specify how the image is displayed in the grid cell.

It should default to Uniform which sounds like what you require however from your description you may either have it set to "Fill", which will fill the cell resulting in cropping, "None" showing it as the original or have specified the image width or height (this may override the Stretch).

<Image Grid.Column="1" Stretch="Uniform" Source="sample.jpg"  />

Setting it to Uniform (or leaving out the Stretch property) and not specifying the width or height will mean it will resize to the maximum possible with out being cropped from either direction. As it is still in the grid it will also centre the image. A scale transform should not be required as the Stretch property will deal with this.

John