ComboBox Class
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
[TemplatePartAttribute(Name="PART_Popup", Type=typeof(Popup))] [StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=typeof(ComboBoxItem))] [LocalizabilityAttribute(LocalizationCategory.ComboBox)] [TemplatePartAttribute(Name="PART_EditableTextBox", Type=typeof(TextBox))] public class ComboBox : Selector
/** @attribute TemplatePartAttribute(Name="PART_Popup", Type=System.Windows.Controls.Primitives.Popup) */ /** @attribute StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=System.Windows.Controls.ComboBoxItem) */ /** @attribute LocalizabilityAttribute(LocalizationCategory.ComboBox) */ /** @attribute TemplatePartAttribute(Name="PART_EditableTextBox", Type=System.Windows.Controls.TextBox) */ public class ComboBox extends Selector
TemplatePartAttribute(Name="PART_Popup", Type=System.Windows.Controls.Primitives.Popup) StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=System.Windows.Controls.ComboBoxItem) LocalizabilityAttribute(LocalizationCategory.ComboBox) TemplatePartAttribute(Name="PART_EditableTextBox", Type=System.Windows.Controls.TextBox) public class ComboBox extends Selector
<ComboBox> Items </ComboBox>
A ComboBox is a composite control that is made up of three controls: Button, TextBox, and Popup. The control allows the user to select from the list or optionally to enter new text in the TextBox. The default behavior of a ComboBox displays a TextBox and a Button with a hidden drop-down list. When the button is clicked the drop-down list appears.
The ComboBox has two modes, one in which the TextBox is editable, and another where the TextBox is not editable. If IsEditable is false, the ComboBox allows a user to choose one item from a preset list of options.
ContentModel: A ComboBox is an ItemsControl. For more information on the content model for ComboBox, see Items Control 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.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
System.Windows.Controls.ItemsControl
System.Windows.Controls.Primitives.Selector
System.Windows.Controls.ComboBox
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.