I have the following XAML code:
<Image Source="a.jpg" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform"/>
and I visually got the following:

( http://img810.imageshack.us/img810/2401/imagestretchuniform.png )
With Stretch="None"
, I got the following:

( http://img28.imageshack.us/img28/1783/imagestretchnone.png )
Now, I want to center the image vertically or horizontally using Stretch="Uniform"
! Only the "smallest" side (with Uniform
) will be centered, on the right. But at the moment, as you can see in the screenshots, the image is simply placed in the upper left corner, even if I defined HorizontalAlignment
and VerticalAlignment
to "Center"
What should I do?
whole code:
<UserControl [...]> <Canvas Width="640" Height="480" Background="#FF881607"> <Image Source="a.jpg" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform"/> </Canvas> </UserControl>
EDIT (solution): Just in case, some1 has the same problem, here is how I solved it:
<Canvas Width="640" Height="480" Background="#FFAA00FF" > <Image Source="z.jpg" Height="480" Width="640"/> </Canvas>
This is EXACTLY the same behavior as HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform"
The image is stretched to Uniform (the image is smaller or larger than the canvas), and it is centered both vertically and horizontally!
source share