In WPF we can XAML <Canvas /> element to create a Canvas control. This is a container control in which we can add child elements by using coordinates which is relative to canvas area. The coordinates can be specified relative to any side of the panel using the Canvas.Left, Canvas.Right, Canvas.Top and Canvas.Bottom. The panel is used mainly used to group 2d graphics element. Some common properties of the Canvas control are as follows…

  • If Left property of Canvas control is set by calling Canvas.Left property then Right property does not work and if Canvas.Top property is set then Canvas.Bottom property does not work and vice versa.
  • The vertical and horizontal alignment on child element did not work. Child elements are placed on position set by the Canvas Left, Top, Right and Bottom properties.
The following code snippet represents use of Canvas control
        <Rectangle Canvas.Left="40" Canvas.Top="40" Width="200" Height="100" Fill="BlanchedAlmond"/>
        <Ellipse Canvas.Right="70" Canvas.Top="110" Width="100" Height="100" Fill="DarkCyan" />
The output of the following code snippet is as follows

Canvas Control in WPF


  Modified On Mar-22-2018 06:09:51 AM

Leave Comment