Windows Phone 7 导航服务 URI?
在我的项目中,我创建了一个名为“Pages”的单独文件夹,用于存储除主页之外的所有页面。我希望从主页导航到这些页面之一。我该怎么做?我没有运气:
NavigationService.Navigate(new Uri("/Pages/Page1.xaml",UriKind.Relative));
我每次都会收到空引用异常。提前致谢! 还有什么方法可以像在 WPF 中那样使用页面构造函数进行导航?
In my project, I have created a separate folder called "Pages" for storing all pages except the main page. I wish to navigate to one of these pages from the main page. How do i do it? I've had no luck with:
NavigationService.Navigate(new Uri("/Pages/Page1.xaml",UriKind.Relative));
I'm getting a null reference exception each time.thanks in advance!
Also is there any way i can navigate using the pages constructor instead like in WPF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NavigationService
特定于页面。如果您尝试从外部调用它,通常会收到NullReferenceException
。NavigationService
is specific to a page. If you are trying to invoke it from outside one, you will generally get aNullReferenceException
.尝试重写 OnNavigateTo() 事件并从那里执行页面导航。你在那里不会得到空异常。
该事件在构造函数加载后立即触发,因此如果您想在页面完全加载之前检查某些条件并执行导航,那么这是理想的位置。
另外,还有一个称为“OnNavigateFrom()”的函数,它在您退出页面时发生。
希望有帮助。
Try overriding the OnNavigateTo() event and perform page navigation from there. You don't get null exception over there.
This event is fired just after the constructor is loaded and hence is ideal place if you want to check for some condition and perform navigation before the page is loaded completely.
Also, there is another called "OnNavigateFrom()" which occurs when you exit the page.
Hope that helps.