public LoginPage() { this.InitializeComponent(); SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += (s, e) => { // Code run when the window is closing if (_mPageArgs != null) { if (_mPageArgs.OnError != null) { _mPageArgs.OnError("User closed the window!"); } } }; }