Share via


Children Property (Canvas)

Gets the collection of child elements on the Canvas.

XAML
<Canvas>
  oneOrMoreUIElements
</Canvas>
Scripting
value = object.Children

XAML Values

oneOrMoreUIElements One or more object elements that derive from UIElement. These can be one or more of the following: Canvas, Ellipse, Glyphs, Image, InkPresenter, Line, MediaElement, Path, Polygon, Polyline, Rectangle, Shape, TextBlock.

Property Value

VisualCollection

The collection of child UIElement objects.

This property is read-only. You can use implicit collection syntax in XAML or methods of the VisualCollection in script to add items or otherwise adjust the existing collection, but you cannot replace it with a different object. The default value is an empty VisualCollection collection.

Remarks

Only two types of UIElement support a Children property: Canvas, and InkPresenter.

The XAML syntax for Children is an example of an implicit collection syntax. In this case, because the property is read-only, neither the explicit property element tag <Canvas.Children> nor the object element for the explicit collection <VisualCollection> is permitted by the XAML parser. The implicit collection syntax of placing one or more child elements as direct child elements of a Canvas object element is the only permitted XAML syntax. For more information about XAML implicit collection syntax, see XAML Syntax Overview.

In scripting, you can get the value of Children and retain it for later operations against the collection, but you cannot set the Children property directly by any means. Instead, you typically use CreateFromXaml to create a single node at a time and then add that node to the VisualCollection using the syntax object.Children.Add(xamlNode).

Objects added to the Children collection are rendered immediately.

InkPresenter is a derived class of Canvas and inherits its Children property. The Children for an InkPresenter render on the InkPresenter surface just as they do on a Canvas. For details on how to mix stroke and child element content, see Remarks in InkPresenter.

Applies To

Canvas, InkPresenter

See Also

XAML Syntax Overview
Silverlight Object Models and Scripting to the Silverlight Plug-in
VisualCollection
UIElement
Root