我正在开发Windows Phone应用程序。在我的应用程序中,第1页上有一个按钮,可以转到第2页,第2页上有另一个按钮,可以转到第3页,当我按后退键时,它会转到第2页,但是当我尝试去再次通过点击按钮进入第3页,我的应用程序崩溃了。
P1 - > P2 - > P3
但是当我按下后退按钮时,它会导航到P2
P3 - > P2
现在,当我再次尝试去P3时,我的应用程序崩溃了:
P2 - > P3(app崩溃)
第2页的代码:
private void show_Click(object sender, RoutedEventArgs e)
{
if (to.Text == "" && from.Text =="" )
{
MessageBox.Show("Please enter station", "ATTENTION!!", MessageBoxButton.OKCancel);
}
else if (station.Contains(from.Text) && station.Contains(to.Text))
{
NavigationService.Navigate(new Uri("/result.xaml?source=" + from.Text + "&destination=" + to.Text, UriKind.RelativeOrAbsolute));
}
else
{
var rlt = MessageBox.Show("you have enter wrong station name\npress OK to enter fresh value ", "ATTENTION!!", MessageBoxButton.OKCancel);
if (rlt == MessageBoxResult.OK)
{
if (station.Contains(from.Text))
{
to.Text = "";
}
else if (station.Contains(to.Text))
{
from.Text = "";
}
else
{
from.Text = "";
to.Text = "";
}
}
}
}
第3页的代码:
protected override void OnBackKeyPress(CancelEventArgs e)
{
NavigationService.Navigate(new Uri("/PAGE2.xaml", UriKind.RelativeOrAbsolute));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string source = "";
string destination = "";
NavigationContext.QueryString.TryGetValue("source", out source);
NavigationContext.QueryString.TryGetValue("destination", out destination);
start.Text = source;
finish.Text = destination;
cal(source, destination);
}