开发者

NullReferenceException when setting NavigationService source

开发者 https://www.devze.com 2023-03-31 12:05 出处:网络
I\'m trying to navigate to MainPage.xaml if access_token isn\'t set. public Menu() { InitializeComponent();

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

  public Menu()
            {
                InitializeComponent();
                if (((App)App.Current).access_token == null) {
                  NavigationS开发者_JAVA技巧ervice.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 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...

0

精彩评论

暂无评论...
验证码 换一张
取 消