Export (0) Print
Expand All

ComboBox.ItemContainerStyle Property

Silverlight

Gets or sets the style applied to the container generated for each item in the combo box.

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

public Style ItemContainerStyle { get; set; }
<ComboBox>
  <ComboBox.ItemContainerStyle>
    inlineStyle
  </ComboBox.ItemContainerStyle>
</ComboBox>
<ComboBox ItemContainerStyle="styleReference"/>

XAML Values

inlineStyle

A single Style object element.

styleReference

A StaticResource reference to a Style.

For information that can help you decide whether to define styles inline or as resources, see Inline Styles and Templates.

Property Value

Type: System.Windows.Style
The style applied to the container generated for each item in the combo box.

Dependency property identifier field: ItemContainerStyleProperty

You can use the ItemContainerStyle to provide a custom appearance for combo box items listed in the drop-down portion. This style does not apply to the selected item displayed in the text box.

The following example demonstrates how to set the ItemContainerStyle property to display a custom style for a list of bound combo box items.


public partial class Page : UserControl
{
    public ObservableCollection<Recording> MyMusic = new ObservableCollection<Recording>();
    public Page()
    {
        InitializeComponent();
        MyMusic.Add(new Recording("Sheryl Crow", "Detours", new DateTime(2008, 2, 5)));
        MyMusic.Add(new Recording("Brandi Carlisle", "The Story", new DateTime(2007, 4,3)));
        MyMusic.Add(new Recording("Patty Griffin", "Children Running Through", new DateTime( 2007, 2, 6)));
        MusicCombo.DataContext = MyMusic;
    }
}

public class Recording
{
    public Recording(){}
    public Recording (string artistName, string cdName, DateTime release)
    {
        Artist = artistName;
        Name = cdName;
        ReleaseDate = release;
    }
    public string Artist { get; set; }
    public string Name { get; set; }
    public DateTime ReleaseDate {get; set;}
}



<Grid.Resources>
    <Style TargetType="ComboBoxItem" x:Key="musicStyle" >
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="FontStyle" Value="Italic" />
    </Style>
</Grid.Resources>

<ComboBox Height="40" Width="200" x:Name="MusicCombo" 
    ItemContainerStyle="{StaticResource musicStyle}" ItemsSource="{Binding}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
                <TextBlock Text="{Binding Path=Artist}" />
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

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

Community Additions

ADD
Show:
© 2014 Microsoft