Create a user control inheriting comboBox. Add a dependency property as 'SelectedText'. create event handler for LostFocus on combo box, in event handler assign the entered value dependency property 'SelectedText'.
do binding on 'SelectedText', in its setter if value is new then ad to collection and set SelectedValue to new one.
Indirectly you have to update source by adding new property in ComboBox.
public class ExtendedComboBox : ComboBox
{
public ExtendedComboBox()
{
this.IsEditable = true;
this.LostFocus += ComboBox_LostFocus;
}
public string SelectedText
{
get
{
return (string)GetValue(SelectedTextProperty);
}
set
{
SetValue(SelectedTextProperty, value);
}
}
public static readonly DependencyProperty SelectedTextProperty = DependencyProperty.Register("SelectedText", typeof(string), typeof(ExtendedComboBox), new FrameworkPropertyMetadata(string.Empty, new PropertyChangedCallback(OnSelectedTextPropertyChanged)));
private static void OnSelectedTextPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
{
}
private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
{
SelectedText = (e.Source as ComboBox).Text??string.Empty;
}
}
// Binding Example
%gt%local:ExtendedComboBox Margin="3" x:Name="ecb" SelectedText="{Binding SelectedText,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding SelectedTextList}">%gt/local:ExtendedComboBox>