0

2 つのページ間で複数の文字列を送信しようとしています。ただし、受信ページはそれを 1 つとして解釈するだけです。これを修正する方法についてのアドバイス。

ページ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 を値として認識しません。

何か助けはありますか?

4

2 に答える 2

2

URI の形式が正しくありません。はパラメータの?先頭を示し、各パラメータは で区切る必要があります&

作成している 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));
}
于 2013-01-13T17:21:20.463 に答える
0

& not ? を使用して、2 番目と追加のパラメーターを追加する必要があります。URL のように: /Page1.xml?param1=x¶m2=y

于 2013-01-13T17:20:52.053 に答える