Navigating to a Frame, when I get on it, I would like to get the name of the source page that I'm coming from in order to execute specific actions depending of the navigation source frame. I've heard that the method to use is OnNavigatedTo by can't figure out how to get the source page... Does anyone knows something about that ? Thanks in advance !
Asked
Active
Viewed 631 times
2 Answers
2
You can check what is the last page on Frame.BackStack:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
PageStackEntry lastEntry = Frame.BackStack.LastOrDefault();
Type lastPageType = lastEntry != null ? lastEntry.SourcePageType : null;
}

Romasz
- 29,662
- 13
- 79
- 154
1
Typically, as Romasz has answered, you'd just inspect the last entry on the back stack. But if you need to know what the last page you were on was even when navigating backward, then you might need to inspect the forward stack also, but it's uncommon to do so.

Community
- 1
- 1

Decade Moon
- 32,968
- 8
- 81
- 101