Wpf textblock text binding not updating
If, later, we decided we needed a web-based API to the same model, we could use the Model unchanged.
If the successor to WPF comes along, and we need to update our application to use it, the Model remains unchanged.
By taking advantage of WPF’s Commanding Infrastructure, we can define ICommand instances in the View Model that the View can directly access via Data Binding.
This provides us a clean way to keep the logic out of the View – again, the View works completely via Data Binding to the View Model.
In MVVM, the View Model sits between the View and the Model, and basically acts similar to an Adapter – it translates the properties and methods of the Model to a form that can be directly used via Data Binding.
The View Model also provides us a place to manage application state and logic.
Again, the Model is the domain-specific data and logic used within your application.
It’s the goal – the “data” you’re working to expose to your users.
As I mentioned in the section on templating, WPF’s design strives to maintain a clear separation between presentation and logic. By separating presentation and logic, WPF creates opportunities for much greater degrees of flexibility in our applications. The Model-View-View Model pattern has one goal – to extend this same flexibility into our applications by creating a clean separation of concerns through our entire application.
Also, if there is no logic in the View itself, it eliminates the risk of “stale” or unused code creeping into the View, which often happens in Windows Forms.
Now that we have the View and the Model defined, we need a way to hook the two things together.
The View Model serves the purpose of adapting the Model to be directly usable by the View.
In order to do this, we take advantage of WPF’s incredible Data Binding support.