2

I have a page that several other pages navigate to. However in some circumstances the user should not see this page, so I want to send them to another page instead.

Rather than update the rest of the calling code, I just want to change this page to handle it.

public MyPage()
{
    Loaded += MyPage_Loaded;

    InitializeComponent();
    // Other stuff
}

void MyPage_Loaded(object sender, RoutedEventArgs e)
{
    if(condition)
       NavigationService.Navigate(someUri);
}

Since the NavigationService isn't available in the constructor I have to hook up to the Loaded event and do the redirect there. The problem is that the page has already been loaded and displayed to the user. There is also a slight delay before redirecting the user.

Is there a better way to do this where the redirect is seamless?

Brandon
  • 68,708
  • 30
  • 194
  • 223

0 Answers0