Home > DeveloperSection > Beginner > Canvas Control in WPF

Canvas Control in WPF

0 Comment(s)
 5130  View(s)
Rate this:

Canvas Control in WPF

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


Don't want to miss updates? Please click the below button!

Follow MindStick