ItemsControl.ItemsPanel Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the template that defines the panel that controls the layout of items.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<itemsControl> <itemsControl.ItemsPanel> singlePanelTemplate </itemsControl.ItemsPanel> </itemsControl>
<itemsControl ItemsPanel="resourceReferenceToPanelTemplate"/>
XAML Values
Property Value
Type: System.Windows.Controls.ItemsPanelTemplateAn ItemsPanelTemplate that defines the panel to use for the layout of the items. The default value for the ItemsControl is an ItemsPanelTemplate that specifies a StackPanel.
Dependency property identifier field: ItemsPanelProperty
To affect the layout of the items in an ItemsControl, you use this property to specify a ItemsPanelTemplate.
The following example creates a ListBox that displays items horizontally. The example sets the ItemsPanel to an ItemsPanelTemplate that has a StackPanel whose Orientation property is set to Horizontal. For this example, src is defined as xmlns:src="clr-namespace:ItemsControlSnippets".
<Grid> <Grid.Resources> <Style x:Key="horizontalListBoxStyle" TargetType="ListBox"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"/> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> <src:Items x:Key="items"/> </Grid.Resources> <ListBox ItemsSource="{StaticResource items}" Style="{StaticResource horizontalListBoxStyle}"/> </Grid>
The following example shows the collection of strings that the ListBox is bound to.
The previous example produces output that resembles the following illustration.
