Reputation: 77
I have a custom user control (UWP) I need to invoke one of its methods when the UWP App enters on suspension mode OnSuspending method (App.cs), another approach is call a method located in MainPage
It is possible to achieve this ?
Upvotes: 1
Views: 284
Reputation: 13850
Your control can implement it's own OnSuspending handler, like this:
public MyUserControl()
{
this.InitializeComponent();
this.Loaded += MyUserControl_Loaded;
this.Unloaded += MyUserControl_Unloaded;
}
private void MyUserControl_Loaded(object sender, RoutedEventArgs e)
{
Application.Current.Suspending += MyUserControl_Suspending;
}
private void MyUserControl_Unloaded(object sender, RoutedEventArgs e)
{
Application.Current.Suspending -= MyUserControl_Suspending;
}
private void MyUserControl_Suspending(object sender, SuspendingEventArgs e)
{
// your control's OnSuspending code here
}
Upvotes: 2