1

I'm trying to navigate to MainPage.xaml if access_token isn't set.

  public Menu()
            {
                InitializeComponent();
                if (((App)App.Current).access_token == null) {
                  NavigationService.Source=new Uri("/MainPage.xaml", UriKind.Relative);//NullReferenceException

                }.../
tshepang
  • 12,111
  • 21
  • 91
  • 136
SevenDays
  • 3,718
  • 10
  • 44
  • 71
  • Presumably `NavigationService` is null. Where is this initialised? – ChrisF Aug 26 '11 at 09:05
  • Could this apply to Windows Phone as well? http://stackoverflow.com/questions/2712218/silverlight-navigationservice-is-always-null –  Aug 26 '11 at 09:15
  • @UrbanEsc The root cause could be the same, there's not much detail from the OP. However I'd be nervous about changing RootFrame in Windows Phone without careful thought. For example: the Silverlight Toolkit uses this technique to support page transition animations, but those guys know what they're doing ;) – Paul Annetts Aug 26 '11 at 09:24

1 Answers1

5

If this is your Main page and you are just starting the application I wouldn't expect that the Silverlight NavigationService is initialized at the time when the MainPage object is first constructed. I'd guess you're creating Menu in the MainPage constructor, so that would explain the NullReferenceException.

You will need to trigger your navigation at a later event in the MainPage. If it were me I'd try the Loaded event first, but you may need to experiment to get this behaviour correct...

Paul Annetts
  • 9,554
  • 1
  • 27
  • 43