Writing the ViewModel layer
Now that we have our model layer implemented, we can move on to write the ViewModel layer. The ViewModel will be responsible for presenting each operation to the UI and offering properties to be filled out by the View layer. Other common responsibilities of this layer are input validation and simple logic to display busy indicators.
At this point, it would be a good idea to include the ServiceContainer
class from the previous chapter in our XamSnap
PCL project, as we will be using it through our ViewModels to interact with the Model layer. We will be using it as a simple option to support dependency injection and Inversion of Control; however, you may use another library of your preference for this.
Normally, we start off by writing a base class for all the ViewModel layers within our project. It's a good place to put some parts of the code that are used by all the subclasses, for example: notification changes, methods, or commonly used interfaces.
Place the following...