使用C#开发Metro 风格应用的路线图 在页面间导航、传值

1、与wp7不同,metro在页面间导航不用指明具体的uri,只需要将页面的类型当作参数传给navigated方法就可以。

this.Frame.Navigate(typeof(BasicPage2));

这里额外介绍一下Frame和Page 类
Frame类主要负责导航和实现 Navigate, GoBack, and GoForward 等方法
Frame更像是多个page的容器

2、使用navigete在页面间传值时,使用第二个参数

this.Frame.Navigate(typeof(BasicPage2), "passValue");

 在导航到接收页面时,通过事件的传入参数来接收值

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string name = e.Parameter as string;
    
   
}

3、导航到其他页面时数据的缓存,防止一些表单在页面导航时丢失,只需要设置当前页面的NavigationCacheMode属性即可

public BasicPage1()
{
    this.InitializeComponent();

    this.NavigationCacheMode = 
        Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
}
原文地址:https://www.cnblogs.com/icuit/p/2478082.html