NavigationService.navigate null reference exception

后端 未结 3 803
名媛妹妹
名媛妹妹 2020-12-06 23:48

I\'m learning WP coding and I have problem that I can\'t solve :/

try
 {
    NavigationService.Navigate(new Uri(\"/edit.xaml\", UriKind.Relative));
 }
 catch         


        
相关标签:
3条回答
  • 2020-12-07 00:01

    Use this.... This solved my problem.

    this.Loaded += (a, b) => {my code}
    
    0 讨论(0)
  • 2020-12-07 00:09

    This solve the problem:

    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/edit.xaml", UriKind.Relative));
    
    0 讨论(0)
  • 2020-12-07 00:24

    Because you get an NullReferenceException, my guess is that you are trying to call NavigationService.Navigate to early, for example in the MainPage constructor.

    Instead, if you want to navigate immedietly when page is loaded for example, try doing it by overriding the OnNavigatedTo event by adding this code to the MainPage class:

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
       NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
    }
    
    0 讨论(0)
提交回复
热议问题