在wp中,使用NavigationService.Navigate导航页面出现错误
我们在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导航页面出现错误的更多相关文章
- WP中的语音识别(下):语音指令
除了系统集成的可以用于搜索.启动应用程序等语音命令外,在我们的应用程序内部还能自己定义语音指令,使得我们的APP能与语音操控结合得更加完全. 语音指令是通过一个XML文件来定义的.比如,咱小舅子开了家 ...
- wp8.1 Study1: 页面导航&页面间值传递
摘要:wp8.1与wp8中很多API是不一样了,wp8.1把以前wp7.x时的api去掉了,更多与win8.1的API相似.比如以下的页面导航和页面之间的值传递 1.页面导航 利用Frame.Navi ...
- 在MVVMLight框架的ViewModel中实现NavigationService
网上已经有很多方法了,比如通过Messenger来实现等等.这里我只讲述一种我比较喜欢的方法,因为它很方便 首先定义一个ViewModel基类,将所有ViewModel子类继承这个基类.在基类中定义 ...
- ios 导航页面
// AppDelegate.m#import "AppDelegate.h"#import "ViewController.h" @interface Ap ...
- 5分钟学会vue中的路由守卫(导航守卫)
在项目开发中每一次路由的切换或者页面的刷新都需要判断用户是否已经登录,前端可以判断,后端也会进行判断的,我们前端最好也进行判断. vue-router提供了导航钩子:全局前置导航钩子 beforeEa ...
- SpringMVC中利用@InitBinder来对页面数据进行解析绑定
同步发布:http://www.yuanrengu.com/index.php/springmvc-user-initbinder.html 在使用SpingMVC框架的项目中,经常会遇到页面某些数据 ...
- iOS 从应用中跳转至系统设置页面里的多种设置页面
我们在开发app过程中很多时候会需要设置系统权限,这时就需要在应用中跳转至系统设置页面权限设置页面,以下是自己结合网上的资料总结的一些经验: 直接从应用中跳转至系统设置中这个应用的权限设置页面 NSU ...
- 解析PHP中的file_get_contents获取远程页面乱码的问题【转】
在工作中,遇到一个问题.我需要将一个网址(该网址是一个json数据的接口,即 打开该网址,在浏览器中显示的是json数据),我使用file_get_contents($url),数据是乱码的. 通过查 ...
- asp.net中当服务器出错时显示指定的错误页面
http://blog.csdn.net/helloxiaoyu/article/details/2943537 此篇文章描述了当异常再ASP.NET中发生时怎样使用C#.NET代码去拦截和相应异常. ...
随机推荐
- bzoj1178
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1178 看ppt http://wenku.baidu.com/link?url=dJv6LNm ...
- .net常考面试题
1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成 ...
- Mysql 时间操作
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度) 1 . 查看当天日期 select current_date(); 2. 查看当天时间 select current_time(); ...
- MVC 控制器详解
Controller: Controllers 文件夹包含负责处理用户输入和响应的控制器类. MVC 要求所有控制器的名称必须以 "Controller" 结尾. 控制器的职责: ...
- python学习Processing
# -*- coding: utf-8 -*-__author__ = 'Administrator'import bisect#排序说明:http://en.wikipedia.org/wiki/i ...
- XSS完全解决方案
xss 为什么不能阻止用户输入不安全数据 比如用户想发一篇标题的文章 1+1>2吗? 为什么不在数据库存的时候就处理好或者接口里处理好 1<2 会被转义为 1<2,放到html中确实 ...
- Vue + vue-router
搞了一天的element-ui,vue-router,把侧栏的导航菜单搞了出来后,试着在菜单上加入链接,研究了下官方提供的文档,发现要使用vue-route. 在项目中安装好vue-route, 对照 ...
- cobol语言基础培训教程
COBOL 是Common Business Oriented Language 的缩写.它不仅是商业数据处理的理想语言,而且广泛用于数据管理领域,因此COBOL 语言也被称为”用于管理的语言”. 一 ...
- 使用gfortran将数据写成Grads格式的代码示例
使用gfortran将数据写成Grads格式的代码示例: !-----'Fortran4Grads.f90' program Fortran4Grads implicit none integer,p ...
- JavaScript 滚动页面到指定元素位置
页面评论功能,当评论较多时,有时须要滚动到评论头部. 能够使用scrollTop方法,加上一点延时动画(animate),可訪问在线演示,代码大体例如以下: <html> <scri ...