In my UWP application, I show an popup and then I need to close it when users (1) minimize the application or (2) bring it to background.
(1) For minimize case, I tried below codes. But the result is when application window is restored from minimized state, the the popup disappears. This is not good.
What I expect is when application window is minimized, the popup is closed at once.
(2) As for the case of taken to background, I have no idea. Please advise.
App.xaml.cs:
this.EnteredBackground += App_EnteredBackground;
private void App_EnteredBackground(object sender, EnteredBackgroundEventArgs e)
{
AppEnteredBackground?.Invoke();
}
MainPage.xaml.cs:
App.AppEnteredBackground += App_EnteredBackground;
private void App_EnteredBackground()
{
this.PopAccountInfo.IsOpen = false;
}
Depending on your scenario, it is recommended that you add an
EnteredBackgroundevent to the codebehind of the page to make it easier to call the popup.Application.Current.EnteredBackground += Current_EnteredBackground;MainPage.xaml
MainPage.xaml.cs