Wpf list binding not updating
So we can get the newly added suppliers from Combo Box's items list in code-behind and persist them.
On loading the application again we can add these 'new' supplier again.
- For the Button, we are setting its Command property - again from the View Model static resource, because we can't access the Data Context here (this why we store the entire view model in resources).
The result is: And upon clicking 'Add' we get: Great, here we can use databinding, MVVM pattern and get the added supplier in our Model.
It is worth mentioning here that you could also use Multi Binding to which you pass in the two collections and get back the full combined collection. This is because now we cannot use a Data Template since we have two different types of objects (Supplier and Button) in our collection.
Normally we use MVVM pattern and we bind the Combo box Items Source property to a collection in our view model. Again we have more than one option, but first let me build the MVVM infrastructure before customizing the Combo Box.
ackground: Let's say we have a list in our model - a list of supplier. The user needs to select a supplier to complete a business case. We have given the 'default' list in XAML so it's kind of hard-coded which is not a good thing, it should ideally come from persistence store like database or an XML file.