Поделиться через


ListBox.ItemContainerStyle Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the style that is used when rendering the item containers.

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

Syntax

'Declaration
Public Property ItemContainerStyle As Style
public Style ItemContainerStyle { get; set; }
<ListBox>
  <ListBox.ItemContainerStyle>
    inlineStyle
  </ListBox.ItemContainerStyle>
</ListBox>
<object ItemContainerStyle="resourceReferenceToStyle"/>

XAML Values

  • inlineStyle
    A single Style object element. That Style would typically have multiple setters that set properties on the item container type being targeted. (For ListBox, that type is ListBoxItem.)

  • resourceReferenceToStyle
    A resource reference to an existing Style from a resources collection.

Property Value

Type: System.Windows.Style
The style applied to the item containers. The default is nulla null reference (Nothing in Visual Basic).

Remarks

Dependency property identifier field: ItemContainerStyleProperty

Examples

The following code example shows how to set the ItemContainerStyle property.

Run this sample

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <Style  x:Key="myLBStyle" TargetType="ListBoxItem">
                <Setter Property="Background" Value="Khaki" />
                <Setter Property="Foreground" Value="DarkSlateGray" />
                <Setter Property="Margin" Value="5" />
                <Setter Property="FontStyle" Value="Italic" />
                <Setter Property="FontSize" Value="14" />
                <Setter Property="BorderBrush" Value="DarkGray" />
            </Style>
        </Grid.Resources>
            <ListBox Height="184"  ItemContainerStyle="{StaticResource myLBStyle}"  HorizontalAlignment="Left" 
                 Margin="23,24,0,0" Name="listBox1" VerticalAlignment="Top" Width="204" >
            <ListBox.Items>
                <ListBoxItem Content="Item1" />
                <ListBoxItem Content="Item2" />
                <ListBoxItem Content="Item3" />
            </ListBox.Items>
        </ListBox>
    </Grid>
</UserControl>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

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