Search code examples
c#uwpwindows-10-mobile

UWP Page navigation indentifier


Hello in UWP I can navigate to another page like:

Frame.Navigate(typeof(AnotherPage), someObject);

and in AnotherPage if I want to retrieve the object:

protected override void OnNavigationTo(NavigationEventArgs e) {
    SomeObject someObject = (SomeObject) e.Parameter;
    //here I would like to know from what page I am navigating
}

Could you tell me how to find out from what page am I navigating? Thanks.


Solution

  • When navigation is done, the previous page gets put on the Frame's BackStack, simply query that collection.

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        SomeObject someObject = (SomeObject)e.Parameter;
    
        PageStackEntry previousPage = Frame.BackStack.Last();
        Type previousPageType = previousPage?.SourcePageType;
    
        base.OnNavigatedTo(e);
    }