Defines an area within which you can explicitly position child elements by using coordinates that are relative to the area.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
is the only panel element that has no inherent layout characteristics. A has default Height and Width properties of zero, unless it is the child of an element that automatically sizes its child elements. Child elements of a are never resized, they are just positioned at their designated coordinates. This provides flexibility for situations in which inherent sizing constraints or alignment are not needed or wanted. For cases in which you want child content to be automatically resized and aligned, it is usually best to use a Grid element.
The ZIndex property determines the order in which child elements that share the same coordinate space appear. A higher ZIndex value for one child element indicates that this element will appear above another child element that has a lower value.
Child elements of a are always given the full size that they desire. As a result, vertical alignment and horizontal alignment have no effect inside a .
is a top-level layout control that you can use for absolute positioning of child content. For painting and drawing, you use brushes and do not have to use a . For more information, see Painting with Solid Colors and Gradients Overview.
By default, panel elements do not receive focus. To compel a panel element to receive focus, set the Focusable property to true.
This example shows how to create and use an instance of .
WindowTitle = "Canvas Sample" 'Create a Canvas as the root Panel Dim myCanvas As New Canvas() myCanvas.Background = Brushes.LightSteelBlue Dim txt1 As New TextBlock txt1.FontSize = 14 txt1.Text = "Hello World!" Canvas.SetLeft(txt1, 10) Canvas.SetTop(txt1, 100) myCanvas.Children.Add(txt1) 'Add a second text element to show how absolute positioning works in a Canvas Dim txt2 As New TextBlock txt2.FontSize = 22 txt2.Text = "Isn't absolute positioning handy?" Canvas.SetLeft(txt2, 75) Canvas.SetTop(txt2, 200) myCanvas.Children.Add(txt2) Me.Content = myCanvas
<Page WindowTitle="Canvas Sample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Canvas Background="LightSteelBlue"> <TextBlock FontSize="14" Canvas.Top="100" Canvas.Left="10">Hello World!</TextBlock> <TextBlock FontSize="22" Canvas.Top="200" Canvas.Left="75">Isn't absolute positioning handy?</TextBlock> </Canvas> </Page>
|How to: Wrap a Border Around the Content of a Canvas||This example shows how to wrap a element with a Border.|
|How to: Absolutely Position Elements in a Canvas||This example shows how to use the control to absolutely position content.|
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.