I haven't had much luck finding the answer through google searches, but is it possible to tell which page a user came from?
Or, send a query string on back button press, so I can tell?
Basically, I have a page that I don't want a user to get to by pressing the back button -- the only way they should get there is if they followed the process from the start. A good example of what I'm trying to do is not allow a user to go back to the confirmation setup while registering for an account after they have already successfully registered. I'd rather them go to the start of registration.
You can use the NavigationService.BackStack property and check the first entry in the back stack in the page as it is navigated to.
If this check needs to be done in several pages, it could be put into a base class. Also, if your situation fits the eula/login scenario mentioned by @Skomski, his answer makes the most sense.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var lastPage = NavigationService.BackStack.FirstOrDefault();
if (lastPage != null && lastPage.Source.ToString() == "/MainPage.xaml")
{
NavigationService.RemoveBackEntry();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With