您的位置:首页 > 其它

WP8页面跳转实现参数传递的多种方法

2014-08-22 11:54 531 查看
方法一:通过WEB传参方式进行传参
开始跳转页:
NavigationService.Navigate(new Uri("/Page/MainPage/XXXXPage.xaml?Address="+address,UriKind.RelativeOrAbsolute));
转入页:
//此方法应该在页面的Loaded方法体中实现
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: