Question

Im creating a very simple Windows Phone 8.1 app in Visual Studio Express. I have added a Hyperlink control, then from that I have double click to go to the relevant VB page.

As instructed by the many tutorials out there I have added the code for the button - which should navigate it to the second page I have created.

Private Sub hyperlinkButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    NavigationService.Navigate(New Uri("/SecondPage.xaml", UriKind.Relative))
End Sub

However VB keeps on giving me the error "NavigationService is not declared"

Searching the error message has given me very little joy so far.

Était-ce utile?

La solution

In Windows Phone 8.1, code for navigation to another page are declared as,

this.Frame.Navigate(typeof(SecondPage));

Autres conseils

You cannot just call the class as you will need to get it from the app (so that the system navigates within the app). This is done by accessing the PhoneApplicationFrame!

It should look something like this:

Private Sub hyperlinkButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Uri uri = New Uri("/SecondPage.xaml", UriKind.Relative);
    ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(uri)
End Sub
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top