C# 从两个不同页面导航到同一页面都传递参数
我想从两个不同的页面p2和p3导航到页面p1。 p2页和p3页都将参数传递给p1页。 以下是p2页和p3页按钮的代码 第p2页:C# 从两个不同页面导航到同一页面都传递参数,c#,silverlight,windows-phone-7,C#,Silverlight,Windows Phone 7,我想从两个不同的页面p2和p3导航到页面p1。 p2页和p3页都将参数传递给p1页。 以下是p2页和p3页按钮的代码 第p2页: private void button1_Click_1(object sender, RoutedEventArgs e) { ListBoxItem l = (ListBoxItem)listBox1.SelectedItem; string s = (string)l.Content; NavigationService.Navigate
private void button1_Click_1(object sender, RoutedEventArgs e)
{
ListBoxItem l = (ListBoxItem)listBox1.SelectedItem;
string s = (string)l.Content;
NavigationService.Navigate(new Uri("/Page1.xaml?ok=" + s, UriKind.RelativeOrAbsolute));
}
第p3页:
private void button1_Click_1(object sender, RoutedEventArgs e)
{
ListBoxItem l = (ListBoxItem)listBox1.SelectedItem;
string s = (string)l.Content;
NavigationService.Navigate(new Uri("/Page1.xaml?ko=" + s, UriKind.RelativeOrAbsolute));
}
我想知道p1页中OnNavigatedTo函数的代码,这样它就可以接收这两个参数并将它们显示在两个不同的文本块中。因为您的参数名称不同,所以对每个参数进行查询并不是什么大问题
string ok = string.Empty;
NavigationContext.QueryString.TryGetValue("ok", out ok);
string ko = string.Empty;
NavigationContext.QueryString.TryGetValue("ko", out ko);