Frage

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.

War es hilfreich?

Lösung

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

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

Andere Tipps

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top