this.NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative)); 导航到SecondPage.xaml
页面间传递参数,通过new uri (string str)通过str 传递参数
string destination = "/SecondPage.xaml";
Color clr = (ContentPanel.Background as SolidColorBrush).Color;
destination += String.Format("?Red={0}&Green={1}&Blue={2}",clr.R, clr.G, clr.B);
this.NavigationService.Navigate(new Uri(destination, UriKind.Relative));
SecondPage.xaml获得传递来的参数
IDictionary<string, string> parameters = this.NavigationContext.QueryString;
if (parameters.ContainsKey("Red"))
{
byte R = Byte.Parse(parameters["Red"]);
byte G = Byte.Parse(parameters["Green"]);
byte B = Byte.Parse(parameters["Blue"]);
}
多个页面之间都使用到的数据(共享数据)
在导航多个实例中保存页面数据
在导航出去之前把值存到PhoneApplicationService
protected override void OnNavigatedFrom(NavigationEventArgs args)
{
if (ContentPanel.Background is SolidColorBrush)
{
Color clr = (ContentPanel.Background as SolidColorBrush).Color;
if (args.Content is MainPage)
(args.Content as MainPage).ReturnedColor = clr;
PhoneApplicationService.Current.State["Color"] = clr;// 保存
}
}
导航回来的时候把值从PhoneApplicationService取出来
protected override void OnNavigatedTo(NavigationEventArgs args)
{
if (PhoneApplicationService.Current.State.ContainsKey("Color"))
{ Color clr = (Color)PhoneApplicationService.Current.State["Color"]; // 取出来
ContentPanel.Background = new SolidColorBrush(clr);
}
}