Updating BaseViewModel

Since most ViewModels in the TripLog app will need to use the navigation service, it makes sense to include it in the BaseViewModel class:

public abstract class BaseViewModel : INotifyPropertyChanged
{
protected INavService NavService { get; private set; }

protected BaseViewModel(INavService navService)
{
NavService = navService;
}

// ...
}

Each of the ViewModels that inherit from BaseViewModel will need to be updated to include an INavService parameter in their constructors that is then passed to its BaseViewModel base class. The BaseViewModel<TParameter> base class needs to be updated to include an INavService constructor parameter as well.

In addition, each ViewModel initialization needs to be updated to pass in an INavService, which can be retrieved from the Xamarin.Forms DependencyService:

  1. Update the MainViewModel instantiation in the MainPage constructor:
      public MainPage()
{
BindingContext = new MainViewModel(DependencyService.Get<INavService>());

// ...
}
  1. Update the DetailViewModel instantiation in the DetailPage constructor:
      public DetailPage()
{
BindingContext = new DetailViewModel(DependencyService.Get<INavService>());

// ...
}
  1. Update the NewEntryViewModel instantiation in the NewEntryPage constructor:
      public NewEntryPage()
{
BindingContext = new NewEntryViewModel(DependencyService.Get<INavService>());

// ...
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.195.236