MessageBox.Show in App Closing/Deactivated events

后端 未结 2 537
鱼传尺愫
鱼传尺愫 2021-01-29 04:16

I have a MessageBox being shown in Application Closing/Deactivated methods in Windows Phone 7/8 application. It is used to warn the user for active timer being disabled because

2条回答
  •  再見小時候
    2021-01-29 04:43

    Move the msgBox code from the app closing events and into your main page codebehind. Override the on back key press event and place your code there. This is how it was done on 7.x:

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
            {
                if (MessageBox.Show("Do you want to exit XXXXX?", "Application Closing", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    // Cancel default navigation
                    e.Cancel = true;
                }
            }
    

    FYI - On WP8 it looks like you have to dispatch the MsgBox Show to a new thread.

    This prompts the user before the app ever actually starts to close in the event model. If the user accepts the back key press is allowed to happen, otherwise its canceled. You are not allowed to override the home button press, it must always go immediately to the home screen. You should look into background agents to persist your timer code through suspend / resume.

提交回复
热议问题