这是一个非常奇怪的情况我在这里。让我们为了简单起见说我有3页。 ' MainPage.xaml ',' SeconPage.xaml '和' ThirdPage.xaml '。我正尝试使用以下代码从'ThirdPage.xaml'导航到'MainPage.xaml':
// Forward user to MainPage
try
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
catch (Exception ete)
{
MessageBox.Show("Error when navigating: " + ete.ToString());
}
由于某些未知原因,这不起作用......没有错误被抛出,没有。它什么都不做。这个代码确实已经执行了我已经通过它周围的一堆MessageBox调用确认了。
当我尝试使用'SecondPage.xaml'中完全相同的代码执行完全相同的操作时。一切都很完美...我不知道如何解决这个问题,特别是如果没有出现错误信息。真的很感激任何帮助!
修改 (@AmanKhandelwal要求的ThirdPage.xaml.cs)
public partial class ThirdPage : PhoneApplicationPage
{
public ThirdPage()
{
InitializeComponent();
}
private void btnForgotPin_Click(object sender, RoutedEventArgs e)
{
// Clear out entire cache
DataCache myCache = new DataCache();
myCache.deleteEntireCache();
// Forward user to login screen
try
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
catch (Exception ete)
{
MessageBox.Show("Error when navigating: " + ete.ToString());
}
}
protected override void OnBackKeyPress(CancelEventArgs e)
{
/* When back button is pressed on this page the app has to close,
* the user is not allowed to interact with the app without providing
* the authentication pin.
*/
throw new ExitException();
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
MessageBox.Show("Hitting OnNavigatedFrom");
}
}
答案 0 :(得分:0)
NavigationService.Navigate(new Uri("/[name_of_your_project];component/[page_name.xaml]", UriKind.Relative));
按照描述进行更改后将其放入。