代码之家  ›  专栏  ›  技术社区  ›  samwize

PhoneApplicationPage退出时的事件

  •  2
  • samwize  · 技术社区  · 14 年前

    当PhoneAppApplicationPage(如MainPage.xaml)退出时,如何处理该事件?

    我尝试处理卸载的事件,但当我退出页面时不会调用它。

    3 回复  |  直到 10 年前
        1
  •  6
  •   Amr H. Abd Elmajeed Judd Lyon    14 年前

    我认为你的意思是这个事件:

     protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
    
            // write exit logic
        }
    

    无论何时离开页面,无论是按后退按钮还是按主页按钮,都会调用此事件。只需将上面的内容粘贴到页面的代码隐藏类中,并根据需要进行调整。

        2
  •  2
  •   mikeesouth    14 年前

    你说出口是什么意思?当用户按后退键时,您可以通过订阅phoneApplicationPage.backkeypress来处理事件。

    例子:

    private void OnBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
    {
        MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to exit?", "Exit?", MessageBoxButton.OKCancel);
        if (messageBoxResult != MessageBoxResult.OK)
            e.Cancel = true;
    }
    

    但是,当用户通过按Home按钮、Search按钮、Toast通知、来电或类似的方式退出应用程序时,称为逻辑删除。您可以在应用程序上处理停用的事件,以在应用程序中保存状态,以便您可以在下次启动应用程序时从用户离开的位置继续。但是你不能“停止”逻辑删除——这样用户就不能退出应用程序。

    阅读此处有关墓碑的更多信息:
    Architecting WP7 - Part 5 of 10: Tombstoning by Shawn Wildermuth

        3
  •  0
  •   Felix Frank    10 年前

    当PhoneAppApplicationPage(mainpage.xaml)退出时, 这就像是闭幕式, MainPage_PointerExited 事件作品 wp8.1 .

    即使这条线是4年前的,我想回答万一 可能对寻找答案的人有帮助。

    Private Sub MainPage_PointerExited(sender As Object, e As PointerRoutedEventArgs) Handles Me.PointerExited
    
        Application.Current.Exit()
    
        'your code goes here
    
    end sub