Building the MainPageViewModel class

Let's add the ViewModelBase class, which will contain the AlertArgs event. Create a new folder called ViewModels, add in a new file called ViewModelBase.cs, and implement the following:

public class ViewModelBase : INotifyPropertyChanged 
    { 
        #region Public Events 
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        public event EventHandler<AlertArgs> Alert; 
 
        #endregion 
 
        #region Public Properties 
 
        public INavigationService Navigation; 
 
        #endregion 

The ViewModelBase class will be similar to the other Xamarin.Forms projects. We have the INotifiedPropertyChanged requirements, another EventHandler for alerts, and the INavigationService for navigation control.

Next, we have the constructor:

 #region Constructor public ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.