Спасибо Мэтту Касто за то, что он направил меня в нужном направлении.
Вот рабочий код:
App.xaml.cs:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
Messenger.Default.Send(new NotificationMessage<AppEvents>(AppEvents.Activated, string.Empty));
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
Messenger.Default.Send(new NotificationMessage<AppEvents>(AppEvents.Deactivated, string.Empty));
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
Messenger.Default.Send(new NotificationMessage<AppEvents>(AppEvents.Closing, string.Empty));
}
ViewModel:
Messenger.Default.Register<NotificationMessage<AppEvents>>(this, n =>
{
switch (n.Content)
{
case AppEvents.Deactivated:
_sessionPersister.Persist(this);
break;
case AppEvents.Activated:
var model = _sessionPersister.Get<TrackViewModel>();
break;
}
});