.NET Framework Class Library for Silverlight
ItemsControl..::.ItemsPanel Property

Gets or sets the template that defines the panel that controls the layout of items.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Syntax

Visual Basic (Declaration)
Public Property ItemsPanel As ItemsPanelTemplate
    Get
    Set
Visual Basic (Usage)
Dim instance As ItemsControl
Dim value As ItemsPanelTemplate

value = instance.ItemsPanel

instance.ItemsPanel = value
C#
public ItemsPanelTemplate ItemsPanel { get; set; }
XAML Property Element Usage
<itemsControl>
  <itemsControl.ItemsPanel>
    singlePanelTemplate
  </itemsControl.ItemsPanel>
</itemsControl>
XAML Attribute Usage
<itemsControl ItemsPanel="resourceReferenceToPanelTemplate"/>

XAML Values

singlePanelTemplate

A single ItemsPanelTemplate object element. That ItemsPanelTemplate would typically have multiple child elements that define the panel layout.

resourceReferenceToPanelTemplate

A resource reference to an existing ItemsPanelTemplate from a resources collection. The resource reference must specify the desired ItemsPanelTemplate by key.

Property Value

Type: System.Windows.Controls..::.ItemsPanelTemplate
An 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.
Remarks

Dependency property identifier field: ItemsPanelProperty

To affect the layout of the items in an ItemsControl, you use this property to specify a ItemsPanelTemplate.

Examples

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.

XAML
<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.

Visual Basic
Public Class Items
    Inherits System.Collections.ObjectModel.ObservableCollection(Of String)

    Public Sub New()
        Add("Item 1")
        Add("Item 2")
        Add("Item 3")
        Add("Item 4")
        Add("Item 5")
    End Sub
End Class
C#
public class Items : 
    System.Collections.ObjectModel.ObservableCollection<string>
{
    public Items()
    {
        Add("Item 1");
        Add("Item 2");
        Add("Item 3");
        Add("Item 4");
        Add("Item 5");
    }
}

The previous example produces output that resembles the following illustration.

ListBox with items arranged horizontally

A ListBox that positions items horizontally.
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Other Resources

Tags :


Page view tracker