Hello,
Welcome to Microsoft Q&A!
Handling of UWP child window closing behavior
If I understand you correctly, user could launch an extra View in your app and you want to make sure that the extra View can't be closed in 10-20s at the beginning. Is that right?
A possible solution is that you could handle the SystemNavigationManagerPreview.CloseRequested in the extra View (Let's say it is called BlankPage1) to make sure user can't close at the beginning. Then you could start a timer and use a flag to indicate when it is allowed to close the extra View.
Besides, it is recommended to tell the user when user close the view.
Here is the code that you could refer to. You could create such a page and test with your code.
public sealed partial class BlankPage1 : Page
{
public bool allowClose = false;
public DispatcherTimer timer;
public BlankPage1()
{
this.InitializeComponent();
// launch a timer
timer = new DispatcherTimer();
timer.Tick += Timer_Tick;
timer.Interval = new TimeSpan(0, 0, 5);
timer.Start();
// handle close event
var sysNavMgr = SystemNavigationManagerPreview.GetForCurrentView();
sysNavMgr.CloseRequested += SysNavMgr_CloseRequested;
}
private void Timer_Tick(object sender, object e)
{
Debug.Write("5s passed");
allowClose = true;
timer.Stop();
}
private void SysNavMgr_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
{
var deferral = e.GetDeferral();
if (!allowClose)
{
e.Handled = true;
}
deferral.Complete();
}
}
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.