开发者

Windows Phone 7 Navigation Service URI?

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?


NavigationService is specific to a page. If you are trying to invoke it from outside one, you will generally get a NullReferenceException.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜