locked
How to get navigation back button tapped event? RRS feed

  • Question

  • User4660 posted

    Is there best way to know page is pop to parent page or pushAsync to children page? A page ---can navigation---> B page---- Can navigation ---> C page. If I'm in page B now. So when OnDisappearing() called, how to know is pushAsync to C page or Pop to A page? I want to Save B page's setting when Pop to A page.

    Thursday, July 17, 2014 12:01 PM

All replies

  • User56129 posted

    When you push or pop a page, in the main navigation page instance, there is an event for both Pushed, and Popped. These two events can tell you which page was pushed, and which page was popped. Here is a short example: var myNav = new NavigationPage(); myNav.Popped += (object sender, NavigationEventArgs e) => { Debug.WriteLine("Page was popped: {0}", e.Page.Title); }; myNav.Pushed += (object sender, NavigationEventArgs e) => { Debug.WriteLine("Page was pushed: {0}", e.Page.Title); };

    Thursday, July 17, 2014 2:37 PM
  • User4660 posted

    @Marshall? thank you.

    Thursday, July 17, 2014 3:19 PM
  • User345452 posted

    @Marshall said: When you push or pop a page, in the main navigation page instance, there is an event for both Pushed, and Popped. These two events can tell you which page was pushed, and which page was popped. Here is a short example: var myNav = new NavigationPage(); myNav.Popped += (object sender, NavigationEventArgs e) => { Debug.WriteLine("Page was popped: {0}", e.Page.Title); }; myNav.Pushed += (object sender, NavigationEventArgs e) => { Debug.WriteLine("Page was pushed: {0}", e.Page.Title); };

    Is this code meant to be located in the App.cs class or elsewhere? These events don't seem to be located in the MainPage object.

    (Sorry for waking up an old thread.)

    Monday, November 27, 2017 3:39 PM
  • User171749 posted

    @Polarts said:

    @Marshall said: When you push or pop a page, in the main navigation page instance, there is an event for both Pushed, and Popped. These two events can tell you which page was pushed, and which page was popped. Here is a short example: var myNav = new NavigationPage(); myNav.Popped += (object sender, NavigationEventArgs e) => { Debug.WriteLine("Page was popped: {0}", e.Page.Title); }; myNav.Pushed += (object sender, NavigationEventArgs e) => { Debug.WriteLine("Page was pushed: {0}", e.Page.Title); };

    Is this code meant to be located in the App.cs class or elsewhere? These events don't seem to be located in the MainPage object.

    (Sorry for waking up an old thread.)

    They come from the NavigationPage. So wherever you declare the NavigationPage (I tend to do it in the App constructor). Make the object and events like below.

    NavigationPage test = new NavigationPage();
                test.Popped += (sender, e) => {
    
                };
    
    Monday, November 27, 2017 4:22 PM