Here I have alternatives in the MVVM framework.
my xaml file:
<ComboBox Name="cmbContains" IsEditable="True" IsTextSearchEnabled="false" ItemsSource="{Binding pData}" DisplayMemberPath="wTitle" Text="{Binding SearchText ,Mode=TwoWay}" > <ComboBox.Triggers> <EventTrigger RoutedEvent="TextBoxBase.TextChanged"> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsDropDownOpen"> <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0"/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </ComboBox.Triggers> </ComboBox>
My cs file:
//ItemsSource - pData //There is a string attribute - wTitle included in the fooClass (DisplayMemberPath) private ObservableCollection<fooClass> __pData; public ObservableCollection<fooClass> pData { get { return __pData; } set { Set(() => pData, ref __pData, value); RaisePropertyChanged("pData"); } } private string _SearchText; public string SearchText { get { return this._SearchText; } set { this._SearchText = value; RaisePropertyChanged("SearchText"); //Update your ItemsSource here with Linq pData = new ObservableCollection<fooClass>{pData.ToList().Where(.....)}; } }
You can see that the comboBox being edited is a string binding (SearchText) After the TextChanged event occurs, a drop-down menu is displayed and the two-way binding updates the value. The ItemsSource element is changed in the cs file when it is included in the set {}; syntax.
The bottom line with the code above
source share