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
}.../
If this is your Main page and you are just starting the application I wouldn’t expect that the Silverlight
NavigationServiceis initialized at the time when theMainPageobject is first constructed. I’d guess you’re creating Menu in the MainPage constructor, so that would explain theNullReferenceException.You will need to trigger your navigation at a later event in the MainPage. If it were me I’d try the
Loadedevent first, but you may need to experiment to get this behaviour correct…