Share via


How to: Specify Control Location in Canvas Controls

The Canvas container is the simplest of the Windows Presentation Foundation (WPF) container controls and allows absolute placement of controls. All controls placed on a Canvas control maintain a fixed distance from one of the Canvas corners. This topic describes how to specify the location of a control that is contained in a Canvas control.

To specify control location in Canvas controls

  1. If you do not already have a Canvas container, drag a Canvas container onto your Window from the Toolbox.

  2. Position a control in the Canvas container.

  3. In XAML view, set either the Canvas.Top or Canvas.Bottom property.

  4. In XAML view, set either the Canvas.Right and Canvas.Left property.

    These properties specify the distance from the control edge to the canvas edge. For example, setting the Canvas.Top property to 31 specifies that the top edge of the control is 31 units from the top edge of the canvas. By setting one vertical property (Canvas.Top or Canvas.Bottom) and one horizontal property (Canvas.Left or Canvas.Right), you specify the corner that the control maintains a fixed distance from.

    Note

    If you set more than one horizontal or vertical property, one of them will be ignored.

See Also

Tasks

How to: Construct a Layout Based on Absolute Positioning

How to: Use Attached Properties

Other Resources

WPF Container Controls

Canvas