How can you align a canvas background in WPF?

10,416

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

  <Canvas>
    <Canvas.Background>
      <ImageBrush ImageSource="someimage.jpg" AlignmentX="Right" 
          AlignmentY="Bottom" Stretch="None" />
    </Canvas.Background>
  </Canvas>
Share:
10,416
Totty
Author by

Totty

I am a programmer.

Updated on July 04, 2022

Comments

  • Totty
    Totty almost 2 years

    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

  • Totty
    Totty over 15 years
    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
    Totty over 15 years
    Exactly what I needed. I looked through all the properties for ImageBrush, but somehow I missed those. Thanks!