WP8页面跳转实现参数传递的多种方法(已完善)

方法一:通过WEB传参方式进行传参
开始跳转页:
NavigationService.Navigate(new Uri("/Page/MainPage/XXXXPage.xaml?Address="+address,UriKind.RelativeOrAbsolute));
转入页:
//此方法应该在页面的Loaded方法体中实现
string address=NavigationContext.QueryString["address"];

判断是否存在:
if (NavigationContext.QueryString.ContainsKey("address"))
            {
               string address=NavigationContext.QueryString["address"];
            }

方法二:通过独立存储方式进行传参
开始跳转页:
IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;
iss["ImageSource"] = image.source;
NavigationService.Navigate(new Uri(" /Page/MainPage/XXXXPage.xaml ", UriKind.Relative));
转入页:
IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;
image.Source = (BitmapImage)iss["ImageSource"];

方法三:通过 PhoneApplicationService来实现传参
开始跳转页:
PhoneApplicationService myService = PhoneApplicationService.Current;
protected override void OnNavigatedFrom(NavigationEventArgs e) {
      myService.State["address"] = " address ";
      base.OnNavigatedFrom(e);
}
转入页:
PhoneApplicationService myService = PhoneApplicationService.Current;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){
    object  address ;
    if (myService.State.ContainsKey(" address ")) {
        if (myService.State.TryGetValue(" address ", out  address )) {
            string address  address .ToString();
        }
    }
    base.OnNavigatedTo(e);
}

方法四:通过App.xaml进行传参(共享参数)
App.xaml:
定义一个或几个用于传参的对象,如 public string Address{set;get;}
开始跳转页: 
(Application.Current as App). Address = "address";
转入页:
string address= (Application.Current as App). Address;

判断是否存在:
 if (PhoneApplicationService.Current.State.ContainsKey("address"))
{
string address
= PhoneApplicationService.Current.State["address"] as string;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值