Using Canvas as a panel

Canvas is the lightweight panel and can be used to position the children at a specific coordinate position within the view. You can imagine it as a HTML div element and position the elements at (x, y) coordinate. The attached properties Canvas.Left, Canvas.Top can be used to position the elements relative to left and top corners, whereas the Canvas.Right and Canvas.Bottom can be used to position the child elements relative to right and bottom corners:

Here's a simple example that demonstrates the TextBlocks positioned at (75, 30) and (220, 75) respectively:

  <Canvas> 
    <TextBlock Text="(75, 30)" Canvas.Left="75" Canvas.Top="30"/> 
    <TextBlock Text="(220, 75)" Canvas.Left="220" Canvas.Top="75"/> 
  </Canvas> 

This is not very flexible as you have to manually move the child controls around and make them align the way you want them to. Use it only when you want complete control over the position of the child controls.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.76.0