I want to catch the NavigationService.Navigating event from my page so that the user cannot move forward. I defined an event handler:
void PreventForwardNavigation(object sender, NavigatingCancelEventArgs e)
{
if (e.NavigationMode == NavigationMode.Forward)
{
e.Cancel = true;
}
}
... and it works great. However, I don’t know exactly where to place this code:
NavigationService.Navigating += PreventForwardNavigation;
If I put it in a page constructor or an initialized event handler, then the NavigationService is still null, and I get a NullReferenceException. However, if I put it in the Loaded event handler for the page, then it is called every time the page moves. If I understand correctly, this means that I process the same event several times.
Is it possible to add the same handler to the event several times (as it would be if I used the Loaded event page to link it)? If not, is there a place between initialization and loading, where can I post this?
source
share