Our friend the Model is responsible for getting and holding onto the data.
The data could come from anywhere, a file, a database, thin air, etc.
Implementing those interfaces in the base class saves us from having to implement them in each and every other View Model. Add a new class to the View Models and name it Main View Model.
Make sure to derive from the Base View Model class.
Right after the Initialize Component method call, add the following: That is all you need to do to set the Data Context of the window which is where the data binding looks to find the data.
This is done by combining the desired flags using a bitwise “OR” and then passing that value into the appropriate Dependency Property. As an example, the Width property on Framework Element is registered with the Affects Measure option.Because there is a lot of stuff going on in here, we are going to take it nice and easy getting through this. The main point of this is the initialization of the Command.The Relay Command is passed the method that it is going to call when the button is clicked.We created a base View Model class to serve as a base from which to build upon and created a derived View Model to bind the data to the View raising a Notify Property Changed event to update the data binding.
We also included in our View Model a command using a Relay Command that would be used from the View to go get the data and the View displayed the data in the WPF data grid control through data binding.
The method is easy as we are just going to copy the same code from the previous article and make minor modifications to it. Most of the action happens in the View Model so it naturally follows that the View Model is the most complex which was my stumbling block.