Initializing MainViewModel

The XamarinFormsNavService custom navigation service we created handles initializing ViewModels automatically when they are navigated to by calling the Init method in BaseViewModel. However, because the main page is launched by default and not via navigation, we will need to manually call the Init method on the page's ViewModel when the page first appears.

Update MainPage by overriding its OnAppearing method to call its ViewModel's Init method:

public class MainPage : ContentPage
{
// ...
protected override async void OnAppearing()
{
base.OnAppearing ();

// Initialize MainViewModel
if (_vm != null)
await _vm.Init();
}
}
..................Content has been hidden....................

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