WP7 — NavigationService.Navigate is complaining that it is not receiving an object reference . . . but why?

后端 未结 2 994
[愿得一人]
[愿得一人] 2021-02-05 18:45

WP7 newb question here.

I have the following code:

public class KeyboardHandler : INotifyPropertyChanged
{
    // lots of methods here

    public void F         


        
2条回答
  •  既然无缘
    2021-02-05 19:01

    The Navigate method is actually part of the non-static NavigationService class. Since it's non-static, you need to create an instance of it. The reason you haven't had to create an instance before is because it's part of the Page object, but since you're not inheriting from the Page object, you don't have access to the NavigationService instance.

    There are various ways around this such as creating an event handler in your usercontrol that your host Page object (e.g. MainPage) can subscribe to and have it fire the NavigationService on its behalf.

    Or you can simply access the NavigationService from the Application host like so:

    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(targetUri);
    

提交回复
热议问题