ItemsPresenter Class
This page is specific to:Microsoft Version:
3.03.5Silverlight 34
.NET Framework Class Library for Silverlight
ItemsPresenter Class

Specifies where items are placed in a control, usually an ItemsControl.

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

'Usage

Dim instance As ItemsPresenter

'Declaration

Public NotInheritable Class ItemsPresenter _
    Inherits FrameworkElement
<ItemsPresenter .../>
Remarks

Use the ItemsPresenter in the ControlTemplate of a control to specify the place in the control’s visual tree where the ItemsPanel is added. The ItemsPanel specifies the panel that is used for the layout of items in the control.

Examples

The following example creates a ControlTemplate for a ListBox and uses an ItemsPresenter to determine where the items in the ListBox are placed.

<Grid>
  <Grid.Resources>
    <Style x:Key="ListBoxTemplate" TargetType="ListBox">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ListBox">
            <Grid>
              <Ellipse Stroke="{TemplateBinding BorderBrush}"
                  StrokeThickness="{TemplateBinding BorderThickness}"
                  Fill="{TemplateBinding Background}"/>
              <ScrollViewer HorizontalScrollBarVisibility="Auto"
                          VerticalScrollBarVisibility="Auto">
                <ItemsPresenter HorizontalAlignment="Center"
                              VerticalAlignment="Center"/>
              </ScrollViewer>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <src:Items x:Key="myItems"/>
  </Grid.Resources>

  <ListBox ItemsSource="{StaticResource myItems}" 
         Style="{StaticResource ListBoxTemplate}"
         Width="250" Height="250" 
         Background="Aquamarine" BorderBrush="Navy" BorderThickness="5"/>
</Grid>

The following example shows the collection of strings to which the ListBox is bound.

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


The preceding example produces output that is similar to the following illustration.

ListBox with a custom ControlTemplate

ListBox with new control template
Inheritance Hierarchy

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.ItemsPresenter
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

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

See Also

Reference

© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View