Search code examples
c#wpfxamlclipping

How do I control clipping in C# or XAML when using UniformToFill with an image


I have an image control in a resizable window with its stretch property set to UniformToFill.

<Image Name="some_image" Stretch="UniformToFill" Margin="0,0,0,0" />

The clipping window is pegged to the top left of the image; resizing chops off the right and bottom of the image.

I want the image to be clipped equally on all sides. Am I being dense and overlooking an obvious solution?

How do I control how the image gets clipped?

(Unrelated: This is my first post to stackoverflow. I just wanted to start off saying, thanks, this site has been amazing resource for me)


Solution

  • The HorizontalAlignment and VerticalAlignment property determine this behavior with an image control.

     <Image Name="some_image" Stretch="UniformToFill" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
    

    Guess i was being dense!