Sunday, December 15, 2013

#971 – Items Property is a Content Property

Every control that derives from ItemsControl (including the ListBox) has an Items property that stores the collection of items represented by the control.

The Items property of an ItemsControl is also its content property.  This means that you can set the value of the Items property directly in XAML by specifying a list of child elements for the control that derives from ItemsControl.

For example, you can explicitly specify the child elements using property element syntax:

<ListBox Margin="15" Width="250" Height="250">
        <ListBoxItem Content="Thing 1"/>
        <ListBoxItem Content="Thing 2"/>