[英]Windows Phone Dev C#: Sending Information between Pages
I am trying to send several strings between two pages. 我想在两页之间发送几个字符串。 However, the receiving page only interprets it as one.
但是,接收页面仅将其解释为一个。 Any advice on how I can fix this.
关于如何解决这个问题的任何建议。
Page 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));
}
Page 2 第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);
}
The receiving page outputs a message saying "0?Player1=" and does not recognize player1 as a value. 接收页面输出一条消息“0?Player1 =”并且不识别player1作为值。
Any help? 有帮助吗?
Your URI is malformed. 您的URI格式错误。 The
?
的
?
indicates the beginning of the parameters, and each parameter must be separated by &
. 表示参数的开头,每个参数必须用
&
分隔。
The URI you're constructing is: 您正在构建的URI是:
Page1.xaml?SelectedIndex=0?Player1=...
的Page1.xaml?的SelectedIndex = 0?PLAYER1 = ...
The URI you should construct is: 你应该构建的URI是:
Page1.xaml?SelectedIndex=0&Player1=...
的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));
}
You should apped the second and any additional parameter with & not ? 您应该使用&而不是第二个和任何其他参数? just like in an URL: /Page1.xml?param1=x¶m2=y
就像在URL中一样:/Page1.xml?param1=x¶m2=y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.