【问题标题】:Pass Data On Page NavigationService.GoBack()在页面 NavigationService.GoBack() 上传递数据
【发布时间】:2015-07-22 12:34:25
【问题描述】:

我创建了一个导航事件,其中 Page1 TextBox1.Text 转移到 Page2 TextBox2.Text

我的第 1 页代码:

    private void button1_Click(object sender, System.Windows.Input.GestureEventArgs e)
    {
        string uri = "/Page1.xaml?Text=";
        uri += TextBox1.Text;
        NavigationService.Navigate(new Uri(uri, UriKind.Relative));
    }

我的 Page2 代码:

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        IDictionary<string, string> parameters = this.NavigationContext.QueryString;
        if (parameters.ContainsKey("Text"))
        {
            TextBox2.Text = parameters["Text"];
        }
    }

上述代码在从 Page1 导航到 Page2 时工作正常,但在尝试使用时出错

    NavigationService.GoBack();  method

当我将文本从 page2 传递到 page1 时,我不想创建 page1 的另一个实例,我只想返回旧实例,但是这样做时我的文本没有传输,请帮助...

【问题讨论】:

标签: windows-phone-7 navigation


【解决方案1】:

查看此链接希望对您有所帮助

Pass Values Between Pages

在第 2 页上,使用

保存数据
PhoneApplicationService.Current.State["Text"] = txtboxvalue.Text;

并且可以使用

在 page1 获取
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (PhoneApplicationService.Current.State.ContainsKey("Text"))
                txtvalue.Text = (string)PhoneApplicationService.Current.State["Text"];


        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多