我们在WP项目中采用页面导航时候,经常会使用以下代码

NavigationService.Navigate(new Uri("/Page1.xaml",UriKind.Relative));

但是,有的时候会出现错误:

"Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationService.Navigate(System.Uri)'

我了解了一下,

http://stackoverflow.com/questions/6003212/wp7-navigationservice-navigate-is-complaining-that-it-is-not-receiving-an-obj

从上面这个答案中可以了解到:

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);

在wp中,使用NavigationService.Navigate导航页面出现错误的更多相关文章

  1. WP中的语音识别(下):语音指令

    除了系统集成的可以用于搜索.启动应用程序等语音命令外,在我们的应用程序内部还能自己定义语音指令,使得我们的APP能与语音操控结合得更加完全. 语音指令是通过一个XML文件来定义的.比如,咱小舅子开了家 ...

  2. wp8.1 Study1: 页面导航&页面间值传递

    摘要:wp8.1与wp8中很多API是不一样了,wp8.1把以前wp7.x时的api去掉了,更多与win8.1的API相似.比如以下的页面导航和页面之间的值传递 1.页面导航 利用Frame.Navi ...

  3. 在MVVMLight框架的ViewModel中实现NavigationService

    网上已经有很多方法了,比如通过Messenger来实现等等.这里我只讲述一种我比较喜欢的方法,因为它很方便 首先定义一个ViewModel基类,将所有ViewModel子类继承这个基类.在基类中定义 ...

  4. ios 导航页面

    //  AppDelegate.m#import "AppDelegate.h"#import "ViewController.h" @interface Ap ...

  5. 5分钟学会vue中的路由守卫(导航守卫)

    在项目开发中每一次路由的切换或者页面的刷新都需要判断用户是否已经登录,前端可以判断,后端也会进行判断的,我们前端最好也进行判断. vue-router提供了导航钩子:全局前置导航钩子 beforeEa ...

  6. SpringMVC中利用@InitBinder来对页面数据进行解析绑定

    同步发布:http://www.yuanrengu.com/index.php/springmvc-user-initbinder.html 在使用SpingMVC框架的项目中,经常会遇到页面某些数据 ...

  7. iOS 从应用中跳转至系统设置页面里的多种设置页面

    我们在开发app过程中很多时候会需要设置系统权限,这时就需要在应用中跳转至系统设置页面权限设置页面,以下是自己结合网上的资料总结的一些经验: 直接从应用中跳转至系统设置中这个应用的权限设置页面 NSU ...

  8. 解析PHP中的file_get_contents获取远程页面乱码的问题【转】

    在工作中,遇到一个问题.我需要将一个网址(该网址是一个json数据的接口,即 打开该网址,在浏览器中显示的是json数据),我使用file_get_contents($url),数据是乱码的. 通过查 ...

  9. asp.net中当服务器出错时显示指定的错误页面

    http://blog.csdn.net/helloxiaoyu/article/details/2943537 此篇文章描述了当异常再ASP.NET中发生时怎样使用C#.NET代码去拦截和相应异常. ...

随机推荐

  1. 算法导论(第三版)习题Exercises4.3(第四章三节)算法导论的一个印刷错误

    本节系列证明都可见4.5节需要说明的有4.3-8,4.3-9两题 4.3-8(本题有误) T(n)=4T(n/2)+n2根据4.5理论,结果为Θ(n2lgn) 4.3-9 m = lgn T(2m) ...

  2. 按每k个结点反转链表

    //按每k个结点反转链表 Node* turn_k(Node* head,int n,int k) { Node* p=head; ;t<k;t++) p=p->next; //为了获取最 ...

  3. eclipse中使用loadrunner java api步骤

    1.使用Eclipse新建一个Java工程,名字任意 2.将"%LoadRunner_Home%\classes\lrapi"目录拷贝到工程中 3.将工程导出为Jar包,譬如:命名 ...

  4. Android AdapterView View的复用机制 分析

    对于ListView.GridView相信大家都不陌生,重写个BaseView,实现对于的几个方法,然后就完毕了我们的界面展示.而且在大部分情况下,我们载入特别多的Item也不会发生OOM,大家也都明 ...

  5. c++11: trailing return type in functions(函数返回类型后置)

    In C++03, the return type of a function template cannot be generalized if the return type relies on ...

  6. 《第一行代码》学习笔记3-活动Activity(1)

    1.活动-一种可以包含用户界面的组件,用于和用户进行交互. <Button android:id="@+id/button_1" android:layout_width=& ...

  7. TortoiseSVN上次文件显示被锁定

    1.可以使用SVN clean up来清除锁定. 2.如果不是本目录锁定,系统提示上一层目录锁定,需要到上一层或者根目录中清除. 3.如果在根目录下都无法clean的话,一般采取的方法是另外找一个目录 ...

  8. 3、HelloKhala示例说明

    最简单的dome程序只需3行代码 int main() { //设置端口号 InetAddress listenAddr(USER_PORT); //将端口号绑定到Server NodeServer ...

  9. vc2015编译protobuf

    下载地址:https://github.com/google/protobuf 1.编译通过cmake生成sln文件来编译用cmd命令 cd 到3.0.0-beta-4\cmake mkdir bui ...

  10. 美化xterm

    很多软件调试时,会打开xterm,不过很难看,字体.背景等等都不好看,网上找到了一个不错的xterm的配置文件 !look and feel xterm.termName: xterm-256colo ...