win8.1 参数传递

在win8.1的程序开发过程中,当程序的画面跳转是,我们常常需要进行参数传递。这里给出两种常见的参数传递方法,如有不正确的地方,请多多指正。


方法一:

1.简单参数传递

//发送

public void Button1_Click(object sender, RoutedEventArgs e)

{

    string Message=“Hello World”

    this.Frame.Navigate(typeof(NextPage), Message);//NextPage 目标页面 Message 参数

}

//接收

protected override void OnNavigatedTo(NavigationEventArgs e)

{

    string GetMessage=(string) e.Parameter;//接收参数

    navigationHelper.OnNavigatedTo(e);

}

2.多参数传递

Navigate()的原型是public bool Navigate(Type sourcePageType, object parameter) ,参数传递类型为object!!!


所以我们可以这样做


public class Messages

{

    public string Message1{ set; get; }

    public string Message2{ set ;get; }

              ........

}

//发送

public void Button1_Click(object sender, RoutedEventArgs e)

{

    Messages msg=new Messages();

    msg.Message1 = "Hello Windows !";

    msg.Message2 = "Hello Microsoft !"

    this.Frame.Navigate(typeof(NextPage), msg);//此处便实现了多参传递

}


方法二

首先引用

using Windows.ApplicationModel.Core;

//画面迁移

public void Button1_Click(object sender, RoutedEventArgs e)

{

    CoreApplication.Properties["Message1"] = "Hello Windows !";

    CoreApplication.Properties["Message2"] = "Hello Microsoft !";

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

}

//参数获取

public void NextPage_Load(object sender, RoutedEventArgs e)

{

    if(CoreApplication.Properties["Message1"] !=null)//一定要判断

    {

        string GetMessage1 = CoreApplication.Properties["Message1"] .ToString();

    }

    if(CoreApplication.Properties["Message2"] !=null)

    {

        string GetMessage2 = CoreApplication.Properties["Message2"] .ToString();

    }

}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值