WP7确定我导航的页面

时间:2010-11-01 19:31:21

标签: silverlight navigation windows-phone-7

我有3页。第1页是搜索条件,第2页是列表,第3页是详细信息。

如果我从第1页转到第2页,我想调用Web服务并将详细信息加载到页面上。

如果我从第3页转到第2页(即使用后退按钮),我不想像我已经拥有的那样重新加载数据。

要确定在激活第2页时该怎么做,我需要知道我来自哪里。

我在导航事件中看不到任何告诉我此事的内容。

有什么想法吗?

干杯

史蒂夫

3 个答案:

答案 0 :(得分:1)

无法按原样使用API​​ / SDK。

然而,你可以让调用页面告诉第3页它叫什么 如何执行此操作的一个示例是在查询字符串上包含条目。即。

NavigationService.NavigateTo(new Uri("page3.xaml?from=page2", UriKind.Relative));

然后,在第3页:

string sourcePage;

if (NavigationContext.QueryString.TryGetValue("from", out sourcePage))
{
    // test the value of sourcePage and act accordingly
}

答案 1 :(得分:1)

或者,您可以向应用程序的资源字典添加新条目,并通过重写OnNavigatedTo方法在下一页上检索它。

增加条目:

App.Current.Resources.Add("from",2);

检索条目:

if(App.Current.Resources.Contains("from")
{
   lastPage = (int)App.Current.Resources["from"];
}

有关更多信息,请参阅以下链接中提供的Charles Petzold书的第6章:
http://www.charlespetzold.com/phone/

答案 2 :(得分:1)

作为一种新的(并且更好的?)解决方案,您应该考虑使用新的(2010年12月9日)Non-Linear Navigation Service