none
WP8.1按返回键出现对话框确认退出,如何实现? RRS feed

答案

  • 您好,

    在windows phone 8.1 中你需要对话框命令来实现确定取消的功能,具体请参考下面的代码:

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                // TODO: Prepare page for display here.
    
                // TODO: If your application contains multiple pages, ensure that you are
                // handling the hardware Back button by registering for the
                // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
                // If you are using the NavigationHelper provided by some templates,
                // this event is handled for you.
                Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }
    
            private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
            {
                MessageDialog msgDialog = new MessageDialog("Your message", "Your title");
    
                //OK Button
                UICommand okBtn = new UICommand("OK");
                okBtn.Invoked = OkBtnClick;
                msgDialog.Commands.Add(okBtn);
    
                //Cancel Button
                UICommand cancelBtn = new UICommand("Cancel");
                cancelBtn.Invoked = CancelBtnClick;
                msgDialog.Commands.Add(cancelBtn);
    
                //Show message
                msgDialog.ShowAsync();
    
            }
    
            private void CancelBtnClick(IUICommand command)
            {
                return;
            }
    
            private void OkBtnClick(IUICommand command)
            {
                Application.Current.Exit();
            }
    更多信息请参考MSDN官方文档:https://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.popups.messagedialog.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 learn WP 2016年2月23日 11:10
    2016年2月23日 8:00
    版主

全部回复

  • 您好,

    在windows phone 8.1 中你需要对话框命令来实现确定取消的功能,具体请参考下面的代码:

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                // TODO: Prepare page for display here.
    
                // TODO: If your application contains multiple pages, ensure that you are
                // handling the hardware Back button by registering for the
                // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
                // If you are using the NavigationHelper provided by some templates,
                // this event is handled for you.
                Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }
    
            private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
            {
                MessageDialog msgDialog = new MessageDialog("Your message", "Your title");
    
                //OK Button
                UICommand okBtn = new UICommand("OK");
                okBtn.Invoked = OkBtnClick;
                msgDialog.Commands.Add(okBtn);
    
                //Cancel Button
                UICommand cancelBtn = new UICommand("Cancel");
                cancelBtn.Invoked = CancelBtnClick;
                msgDialog.Commands.Add(cancelBtn);
    
                //Show message
                msgDialog.ShowAsync();
    
            }
    
            private void CancelBtnClick(IUICommand command)
            {
                return;
            }
    
            private void OkBtnClick(IUICommand command)
            {
                Application.Current.Exit();
            }
    更多信息请参考MSDN官方文档:https://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.popups.messagedialog.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 learn WP 2016年2月23日 11:10
    2016年2月23日 8:00
    版主
  • 谢谢你的回答。
    2016年2月23日 11:10