0

我想从 2 个不同的页面 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(new Uri("/Page1.xaml?ok=" + s, UriKind.RelativeOrAbsolute));
}

第 3 页:

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 函数的代码,以便它可以接收两个参数并将它们显示在 2 个不同的文本块中。

4

1 回答 1

0

由于您的参数名称不同,因此查询每个参数都不是什么大问题。

string ok = string.Empty;
NavigationContext.QueryString.TryGetValue("ok", out ok);

string ko = string.Empty;
NavigationContext.QueryString.TryGetValue("ko", out ko);
于 2012-11-16T18:30:54.423 回答