Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ComboBoxItem Class

Implements a selectable item inside a ComboBox.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.ComboBox)] 
public class ComboBoxItem : ListBoxItem
/** @attribute LocalizabilityAttribute(LocalizationCategory.ComboBox) */ 
public class ComboBoxItem extends ListBoxItem
LocalizabilityAttribute(LocalizationCategory.ComboBox) 
public class ComboBoxItem extends ListBoxItem
<ComboBoxItem>
  Content
</ComboBoxItem>

NoteNote:

By default the HorizontalAlignment of a ComboBoxItem is set to Stretch. The default horizontal position of a StackPanel is Center. If you set the Width property of a ComboBoxItem through a StackPanel, the panel's default is applied and the item will be centered.

ContentModel: A ComboBoxItem is a ContentControl. For more information on the content model for ComboBoxItem, see ContentControl Content Model.

In the following example, the ComboBox contains three items. The control is in its collapsed position, which is the default state, until the user clicks the Button on the right side of the control.

<ComboBox Text="Is not open">
    <ComboBoxItem MouseMove="OnHover" Name="cbi1">Item1</ComboBoxItem>
    <ComboBoxItem MouseMove="OnHover" Name="cbi2">Item2</ComboBoxItem>
    <ComboBoxItem MouseMove="OnHover" Name="cbi3">Item3</ComboBoxItem>
</ComboBox>

cbox = new ComboBox();
cbox.Background = Brushes.LightBlue;
cboxitem = new ComboBoxItem();
cboxitem.Content = "Created with C#";
cbox.Items.Add(cboxitem);
cboxitem2 = new ComboBoxItem();
cboxitem2.Content = "Item 2";
cbox.Items.Add(cboxitem2);
cboxitem3 = new ComboBoxItem();
cboxitem3.Content = "Item 3";
cbox.Items.Add(cboxitem3);

cv2.Children.Add(cbox);

For the complete sample, see ComboBox Sample.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
               System.Windows.Controls.ContentControl
                 System.Windows.Controls.ListBoxItem
                  System.Windows.Controls.ComboBoxItem

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft