WinPhone 开发(1)-----在 XAML 页面之间浏览和数据的传递、保留以及恢复

  使用控件HyperlinkButton实现XAML页面之间的浏览,使用方法:设置HyperlinkButton的NavigateUri为"/ProjectName;component/folder/PageName.xaml" ,其中ProjectName、PageName根据实际情况来改变。如果有XAML页面时建立在一个文件夹里面,那么就要加上文件名字folder。
  换而言之,利用HyperlinkButton导航到另一个XAML页面把NavigateUri设置为"/工程名;component/XAML页面的相对路径"。

  数据的传递:使用QueryString获取NavigateUri中的键值对。
  
  demo:NavigateUri="/Testnavigation;component/Views/Page1.xaml=id=1"

  

1  private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
2 {
3 string id = "";
4 if (NavigationContext.QueryString.TryGetValue("id", out id))
5 {
6 textBox1.Text = String.Format("Value:{0}", id);
7 }
8 }


  数据的保留与恢复:重写方法

 1 PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
2 // retain the value of the textbox
3 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)

4 {
5 phoneAppService.State["myValue"] = textBox1.Text;
6 base.OnNavigatedFrom(e);
7 }
8 // try to get the value which is retained
9 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

10 {
11 object someObject;
12 if (phoneAppService.State.ContainsKey("myValue"))
13 {
14 if (phoneAppService.State.TryGetValue("myValue", out someObject))
15 {
16 textBox1.Text = someObject.ToString();
17 }
18 }
19 base.OnNavigatedTo(e);
20 }





一步一脚印,自己的路自己走


转载于:https://www.cnblogs.com/crazypig/archive/2012/02/27/2370435.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值