Hello,
Welcome to our Microsoft Q&A platform!
You have two ways to achieve The way to handle properties inside the page in the application lifecycle event.
(Take MainPage
as an example)
1. Registering Application Lifecycle Events in a Page
public MainPage()
{
this.InitializeComponent();
Application.Current.Suspending += Current_Suspending;
Application.Current.Resuming += Current_Resuming;
}
private void Current_Resuming(object sender, object e)
{
// Because it is a method registered in the Page, you can access the properties in the Page
}
private void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
// Because it is a method registered in the Page, you can access the properties in the Page
}
2. Create an accessible Page instance and access it in the App class
MainPage
public static MainPage Current;
public MainPage()
{
this.InitializeComponent();
Current = this;
}
App
public App()
{
this.InitializeComponent();
this.Suspending += App_Suspending;
this.Resuming += App_Resuming;
}
private void App_Resuming(object sender, object e)
{
if (MainPage.Current != null)
{
var capture = MainPage.Current._capture;
// do other things
}
}
private void App_Suspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
if(MainPage.Current != null)
{
var capture = MainPage.Current._capture;
// do other things
}
deferral.Complete();
}
Thanks