Search code examples
xamlwindows-8windows-store-apps

Windows 8 Image UniformFill centered


I have a little problem, I have a group item which I want to give a background image which it should scale keeping it's correct dimensions but by default it shows the image from the top left, I want the image to be centered.

Here is an illustration to further explain my problem. (the gray part is what is clipped)

My problem

And I have this XAML

<Image Source="/url/to/image.jpg" Stretch="UniformToFill"/>

Solution

  • I managed to solve my problem, I made the image larger than the container it was placed in and vertical aligned it in the center.

    <Grid HorizontalAlignment="Left" Width="250" Height="125">
        <Image Source="/url/to/image.jpg" Stretch="UniformToFill" Height="250" Margin="0" VerticalAlignment="Center"/>
    </Grid>
    

    The overflow of the image was invisible :)