1

I want to use NavigationService.Navigate(new Uri(uri, UriKind.Relative)); in the page constructor. But i get a NullReferenceException. How to solve this problem?

  • Please go through the links [http://stackoverflow.com/questions/25642/when-is-navigationservice-initialized](http://stackoverflow.com/questions/25642/when-is-navigationservice-initialized) [http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx](http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx) [http://msdn.microsoft.com/en-us/library/ms750478.aspx](http://msdn.microsoft.com/en-us/library/ms750478.aspx) – Amal Dev Jul 29 '12 at 09:31

1 Answers1

0

A Page can only get a reference to its NavigationService when Page raises the Loaded event. If you subscribe to loaded event of the page, then you will get NavigationService instance.

public Home()
    {
        InitializeComponent();
        this.Loaded += (s, e) =>
                           {
                               var ns = NavigationService;
                               ns.Navigate(new Uri("/About", UriKind.Relative));
                           };
    }
Sergiy Kozachenko
  • 1,399
  • 11
  • 31