【问题标题】:Windows Phone Dev C#: Sending Information between PagesWindows Phone Dev C#:在页面之间发送信息
【发布时间】:2013-01-13 16:46:48
【问题描述】:

我正在尝试在两个页面之间发送多个字符串。但是,接收页面仅将其解释为一个。关于如何解决此问题的任何建议。

第 1 页

private void button1_Click(object sender, RoutedEventArgs e)
        {
            string urlofdestinationpage = "/Page1.xaml";
            urlofdestinationpage += string.Format("?SelectedIndex=" + playersList.SelectedIndex);
            urlofdestinationpage += string.Format("?Player1=" + textBox1.Text);
            NavigationService.Navigate(new Uri(urlofdestinationpage, UriKind.Relative));
        }

第 2 页

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            IDictionary<string, string> x = this.NavigationContext.QueryString;
            String size = Convert.ToString(x["SelectedIndex"]);
            MessageBox.Show(size);
String player = Convert.ToString(x["Player1"]);
                MessageBox.Show(player1);
            base.OnNavigatedTo(e);
        }

接收页面输出一条消息“0?Player1=”并且不将 player1 识别为值。

有什么帮助吗?

【问题讨论】:

    标签: c# .net windows vb.net windows-phone-7


    【解决方案1】:

    您的 URI 格式错误。 ?表示参数的开头,每个参数必须用&amp;隔开。

    您正在构建的 URI 是:

    Page1.xaml?SelectedIndex=0?Player1=...

    你应该构造的 URI 是:

    Page1.xaml?SelectedIndex=0&Player1=...

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        string urlofdestinationpage = "/Page1.xaml";
        urlofdestinationpage += string.Format("?SelectedIndex=" + playersList.SelectedIndex);
        urlofdestinationpage += string.Format("&Player1=" + textBox1.Text);
        NavigationService.Navigate(new Uri(urlofdestinationpage, UriKind.Relative));
    }
    

    【讨论】:

      【解决方案2】:

      您应该使用 & not 应用第二个参数和任何附加参数?就像在 URL 中一样:/Page1.xml?param1=x&param2=y

      【讨论】:

        猜你喜欢
        • 2016-07-24
        • 2021-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多