我正在为Windows Phone 7构建一个应用程序,我需要显示一个带有确定和取消按钮的消息框。当按下确定按钮时,我想导航到新页面,当按下取消按钮时,我想要保持在同一页面:
我写的代码是:
public Donate()
{
InitializeComponent();
MessageBoxResult result =
MessageBox.Show("This Will Take You Out Of The App And Forward You To Our Contribution Website!",
"", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
donation.Source = new Uri("http://mobiledonation.vzons.com/ArvindKejriwal", UriKind.Absolute);
donation.Loaded += (object sender, RoutedEventArgs e) =>
{
donation.Navigate(new Uri("http://mobiledonation.vzons.com/ArvindKejriwal", UriKind.Absolute));
};
}
else
NavigationService.Navigate(new Uri("/AAP.xaml", UriKind.Relative));
}
现在问题是,当按下取消按钮时,我在语句
中得到一个Null引用异常NavigationService.Navigate(new Uri(“/ AAP.xaml”,UriKind.Relative));
确定按钮工作正常但是当按下取消按钮时我想留在同一页面,即AAP.xaml。我怎样才能做到这一点?