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 ViewModelBase(INavigationService navigation, IMethods methods) { Navigation = navigation; _methods ...