views:

2453

answers:

3

I have set a canvas' background to an image of a company logo. I would like for this image to be aligned to the bottom right corner of the canvas.
Is it possible to do this, or would it require for the image to be added into the canvas as a child? That would not work with this program as all children of the canvas are handled differently.

Thank You

A: 

AFAIK The WPF Canvas needs child UI elements to be positioned using absolute co-ordinates. To achieve the right-bottom-anchored effect, I think you'd need to handle the window resize event, recalculate and apply the Top,Left co-ordinates for the child Image element to always stick to the right buttom corner.

<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>
Gishu
Well, yes and no. The solution I am looking for would alter the Canvas.Background image to be positioned differently. Not a child of the canvas. Also, I believe the easier way to handle the child as you describe would be to set the Canvas.Bottom and Canvas.Right to 0. No need to update then.
Totty
Right you are.. Attached properties are a pain to remember.. so now each child has Width and height + 4 attached props for canvas named Top, Left, Bottom and Right... sheesh! :)
Gishu
A: 

How about containing the canvas and image inside of a Grid control like so?

<Window ...>
  <Grid>
    <Canvas/>
    <Image HorizontalAlignment="Right" VerticalAlignment="Bottom" .../>
  <Grid>
</Window>
Alan Le
+6  A: 

Will this work? (It worked for me, anyway.)

  <Canvas>
    <Canvas.Background>
      <ImageBrush ImageSource="someimage.jpg" AlignmentX="Right" 
          AlignmentY="Bottom" Stretch="None" />
    </Canvas.Background>
  </Canvas>
Kyralessa
Exactly what I needed. I looked through all the properties for ImageBrush, but somehow I missed those. Thanks!
Totty