Panel.Children Property

Definition

Gets a UIElementCollection of child elements of this Panel.

C#
public System.Windows.Controls.UIElementCollection Children { get; }

Property Value

A UIElementCollection. The default is an empty UIElementCollection.

Examples

The following code example demonstrates how to use the Children property to add a UIElement child to a Panel element.

C#
StackPanel myStackPanel = new StackPanel();
Button myButton = new Button();
myButton.Content = "Press me";
myStackPanel.Children.Add(myButton);

Remarks

The Children collection of a Panel element can only consist of UIElement objects. Adding a UIElement child to a Panel implicitly adds it to the UIElementCollection for the Panel element.

Do not use this collection with derived Panel classes; use the InternalChildren collection instead.

This property returns null if the Panel is data bound.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also