The ComboBox in WPF allows users to select an item from the list, but by default does not allow them to edit the text in the combo box. The ComboBox control in Windows Forms on the other hand by default does allow users to enter "free text" into the combo box, in addition to selecting items from the list. In Windows Forms this behavior can be changed, removing the "free text" facility by setting the confusingly named DropDownStyle property to DropDownList. Can we do the opposite in WPF and allow users to edit the text?
Fortunately you can do this in WPF easily by setting the IsEditable property to True as shown below.
Xaml Code (June 06 CTP)
<Window x:Class="LearnWPF.EditableComboBox.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LearnWPF.EditableComboBox" Height="300" Width="300"
>
<Window.Resources>
<XmlDataProvider x:Key="items" XPath="//item">
<x:XData>
<items >
<item>01</item>
<item>02</item>
<item>03</item>
</items>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid>
<ComboBox IsEditable="True" DataContext="{StaticResource items}"
ItemsSource="{Binding}"/>
</Grid>
</Window>
Its worth noting that while this change may be simple to make in the Xaml it may also require some changes in your C# or VB.NET application code - you may need to handle more than the SelectionChanged event on the combo box (since users may start entering values outside the range of values in the list and the SelectionChanged will cease to fire). You also can no longer rely on the SelectedValue and SelectedItem properties of the combo box having a non-null value.
»