在wp中,使用NavigationService.Navigate导航页面出现错误

发布时间:2017-3-30 22:37:43 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"在wp中,使用NavigationService.Navigate导航页面出现错误",主要涉及到在wp中,使用NavigationService.Navigate导航页面出现错误方面的内容,对于在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);

上一篇:java内部类
下一篇:android 中设置背景颜色渐变

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款