Wpf selectedvalue not updating
In WPF, we use MVVM (Model–view–viewmodel) pattern, it put the Model and View in MVC pattern much closer with the help of the data binding technique: The logic is simple: the View and the View Model have the same structure and they are binded together, so when I changed the View Model, the View will automatically presents the View Model.
Then all the “set” and “get” works are no longer needed once the View and View Model are binded.
Data Context must be a object, this object is the “View Model” of our GUI and all the data bindings will be done on this object.
If it is not a Observable Collection, the List Box can not notice its changes.
If it is not public, the List Box can not get access to it. Except defining the Data Binding in xaml, we can also achieve the same functionality dynamically in the code: Attention, when the Items Source is defined, the List Box’s traditional data model List Box. The Items is now null, so when you try to do Items.
The code in the View Model first creates the List, and then creates a Collection View based on that list.
This allows us to set the Current Item from the View Model as well as get notified whenever the Current Item changes.