How to raise / handle the SelectionChanged event of WPF’s ComboBox using the MVVM pattern?
Explain in detail please I am new to WPF.
What I want, is to do some operations when the ComboBox item selection changed. How can I achieve it, in an MVVM way?
MVVM solution:
Bind the
ItemsSourceandSelectedItemproperties of theComboBoxto properties in your ViewModel:In MainViewModel.cs:
Code-behind solution:
If you don’t want to use MVVM, you can add use this:
And add this in MainWindow.xaml.cs: