【问题标题】:c# Moving data from one xaml to another xaml in UWPc#在UWP中将数据从一个xaml移动到另一个xaml
【发布时间】:2017-03-22 08:04:59
【问题描述】:

是否可以将数据从一个 xaml 移动到另一个 xaml?

在 MainPage 我有文本框,我可以在其中编写数字和添加“5”并导航到 Page1 的按钮, 在第 1 页上,我有要显示结果的文本块。

例如 主页

文本框 = 5,按下按钮

第1页 文本块 = 10

我找不到任何关于 UWP 的信息。

【问题讨论】:

    标签: c# uwp


    【解决方案1】:

    您可以通过传递参数在页面之间共享数据。

    var value = int.Parse(textbox.Text) + 5; // make sure you handle faulty input
    Frame.Navigate(typeof(Page1), value);
    

    Page1 中,您可以使用此覆盖访问该值:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
    
        var value = (int)e.Parameter; // this should be 10
    
        // ... do what you need with that value
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-10
      • 1970-01-01
      • 2010-10-06
      相关资源
      最近更新 更多