Updated: February 2009
Represents a selection control with a drop-down list that can be shown or hidden by clicking the arrow on the control.
Namespace:
System.Windows.Controls
Assembly:
PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
<TemplatePartAttribute(Name := "PART_Popup", Type := GetType(Popup))> _
<StyleTypedPropertyAttribute(Property := "ItemContainerStyle", StyleTargetType := GetType(ComboBoxItem))> _
<LocalizabilityAttribute(LocalizationCategory.ComboBox)> _
<TemplatePartAttribute(Name := "PART_EditableTextBox", Type := GetType(TextBox))> _
Public Class ComboBox _
Inherits Selector
[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
[TemplatePartAttribute(Name = L"PART_Popup", Type = typeof(Popup))]
[StyleTypedPropertyAttribute(Property = L"ItemContainerStyle", StyleTargetType = typeof(ComboBoxItem))]
[LocalizabilityAttribute(LocalizationCategory::ComboBox)]
[TemplatePartAttribute(Name = L"PART_EditableTextBox", Type = typeof(TextBox))]
public ref class ComboBox : public Selector
public class ComboBox extends Selector
XAML Object Element Usage
<ComboBox>
Items
</ComboBox>
The ComboBox allows the user to select an item from a drop-down list or optionally to enter new text in the text box of the control.
The IsEditable and IsReadOnly properties specify how the ComboBox behaves when the user does one of the following:
Enters a string to select an item in the ComboBox.
Enters a string that does not correspond to an item in the ComboBox.
Selects part of the string that is in the text box.
Copies or pastes a value into the text box.
The following table describes the actions the user can and cannot take, depending on the values of IsEditable and IsReadOnly.
|
IsReadOnly is true |
IsReadOnly is false |
|---|
IsEditable is true | Cannot select an item in the ComboBox by entering a string. Cannot enter a string that does not correspond to an item in the ComboBox. Can select part of the string in the ComboBox text box. Can copy the string in the ComboBox text box, but cannot paste a string into the ComboBox text box.
| Can select an item in the ComboBox by entering a string. Can enter a string that does not correspond to an item in the ComboBox. Can select part of the string in the ComboBox text box. Can copy or paste the string in the ComboBox text box.
|
IsEditable is false | Can select an item in the ComboBox by entering a string. Cannot enter a string that does not correspond to an item in the ComboBox. Cannot select part of the string in the ComboBox. Cannot copy or paste the string in the ComboBox.
| Can select an item in the ComboBox by entering a string. Cannot enter a string that does not correspond to an item in the ComboBox. Cannot select part of the string in the ComboBox. Cannot copy or paste the string in the ComboBox.
|
The IsReadOnly property has an effect only if IsEditable is true.
The ComboBox is an ItemsControl, so it can display content other than simple strings. For example, you can create a ComboBox that contains a list of images. When you have content other than strings in the ComboBox, a nonsensical string might appear in the ComboBox when the drop-down list is hidden. To display a string in the ComboBox when it contains non-string items, use the TextSearch..::.Text or TextSearch..::.TextPath attached property.
Content Model: ComboBox is a ItemsControl. Its content properties are Items and ItemsSource. For more information on the content model for ComboBox, see Controls Content Model Overview.
Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.
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..::.ItemsControl
System.Windows.Controls.Primitives..::.Selector
System.Windows.Controls..::.ComboBox
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 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0
Reference
Other Resources