How can you align canvas background in WPF?

I set the canvas background to the image of the company logo. I would like this image to be aligned in the lower right corner of the canvas.
Is it possible to do this, or would it require that the image be added to the canvas as a child? This will not work with this program, since all children of the canvas are handled differently.

thanks

+6
alignment wpf canvas
source share
4 answers

Will this work? Anyway, this worked for me.)

<Canvas> <Canvas.Background> <ImageBrush ImageSource="someimage.jpg" AlignmentX="Right" AlignmentY="Bottom" Stretch="None" /> </Canvas.Background> </Canvas> 
+16
source share

AFAIK WPF Canvas requires that the children of the user interface are positioned using absolute coordinates. To achieve the “right shot” effect, I think you need to handle the window resize event, recalculate and apply the “Up”, “Left” coordinates for the “Image” child element, to always adhere to the right corner of the sleeve.

 <Window x:Class="HelloWPF.Window1" xmlns... Title="Window1" Height="300" Width="339"> <Canvas> <Image Canvas.Left="195" Canvas.Top="175" Height="87" Name="image1" Stretch="Fill" Width="122" Source="dilbert2666700071126ni1.gif"/> </Canvas> </Window> 
0
source share

What about the contents of the canvas and the image inside the grid control?

 <Window ...> <Grid> <Canvas/> <Image HorizontalAlignment="Right" VerticalAlignment="Bottom" .../> <Grid> </Window> 
0
source share

This is my solution using the border inside the canvas to align the image. This solution works well when resizing the canvas:

 <Canvas x:Name="MiCanvas" Height="250" Width="500" Background="Aqua"> <Border x:Name="MiBorderImage" Width="{Binding ElementName=MiCanvas, Path=ActualWidth}" Height="{Binding ElementName=MiCanvas, Path=ActualHeight}" Background="Transparent"> <Image x:Name="MiImage" Source="/GraphicsLibrary/Logos/MiLogo.png" HorizontalAlignment="Right" VerticalAlignment="Bottom" Stretch="None" /> </Border> </Canvas> 
0
source share

All Articles