Windows phone 7 带参数的WP7导航
我有一个有3页P1、P2和P3的应用程序 当应用程序从P2导航到P1时,它会传递一个参数 在P1上,我获取参数值,并显示一个messagebox 这工作正常,问题出在以下情况: P2->P1,应用程序使用后退按钮显示消息,P1->P3,P3->P1,应用程序使用P2的参数值再次显示消息,但不应显示任何消息 这是P1的代码:Windows phone 7 带参数的WP7导航,windows-phone-7,Windows Phone 7,我有一个有3页P1、P2和P3的应用程序 当应用程序从P2导航到P1时,它会传递一个参数 在P1上,我获取参数值,并显示一个messagebox 这工作正常,问题出在以下情况: P2->P1,应用程序使用后退按钮显示消息,P1->P3,P3->P1,应用程序使用P2的参数值再次显示消息,但不应显示任何消息 这是P1的代码: protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnN
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
String payment = "";
if (NavigationContext.QueryString.TryGetValue("payment", out payment)) {
if (payment == "no")
{
MessageBox.Show("Your payment failed!.",
"Error", MessageBoxButton.OK);
}
}
}
这是P2的代码:
NavigationService.Navigate(new Uri("/MainPage.xaml?payment=no", UriKind.Relative));
P3不传递任何参数
为什么应用程序在从P3导航到P1时显示消息,这有什么问题
任何帮助都将不胜感激。覆盖P1上的
on navigated to
事件,并检查后退按钮是否按如下方式使用:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
//if the page transition is occurred by pressing back button.
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
{
//do or do not do something
}
}
覆盖P1上的
OnNavigatedTo
事件,并检查后退按钮是否按如下方式使用:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
//if the page transition is occurred by pressing back button.
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
{
//do or do not do something
}
}
您可以在第一次使用该键/值对后,尝试从NavigationContext中删除该键/值对
if (NavigationContext.QueryString.TryGetValue("payment", out payment)) {
if (payment == "no")
{
MessageBox.Show("Your payment failed!.",
"Error", MessageBoxButton.OK);
}
NavigationContext.QueryString.Remove("payment");
}
您可以在第一次使用该键/值对后,尝试从NavigationContext中删除该键/值对
if (NavigationContext.QueryString.TryGetValue("payment", out payment)) {
if (payment == "no")
{
MessageBox.Show("Your payment failed!.",
"Error", MessageBoxButton.OK);
}
NavigationContext.QueryString.Remove("payment");
}
试试这个,我希望它能起作用
String _oldUrl;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
String url = e.Uri.OriginalString;
if(url!=_oldUrl)
{
//do work here
_oldUrl = url;
}
}
试试这个,我希望它能起作用
String _oldUrl;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
String url = e.Uri.OriginalString;
if(url!=_oldUrl)
{
//do work here
_oldUrl = url;
}
}