You can connect the base class of the page to the OnNavigatingTo event and call the method on your ViewModel. I don't have VS with me, but the pseudocode will be:
in MyBasePAge: Page
public void OnNavigatingTo(object sender, eventargs e)
{
var vm = this.DataContext as BaseViewModel;
if(vm != null)
{
vm.Initialize();
}
}
you can do the same before leaving the page:
public void OnNavigatingFrom(object sender, eventargs e)
{
var vm = this.DataContext as BaseViewModel;
if(vm != null)
{
vm.Save();
}
}
source
share