当我触发点击事件导航到 LocationDetail 时,如下所示:
NavigationService.Navigate(new Uri("/LocationDetails.xaml", UriKind.Relative));
应用程序崩溃并且调试器打开 App.xaml.cs 在此代码中突出显示:
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
Debugger.Break();
}
}
有谁知道为什么会这样。类中是否存在错误或它会这样做的原因?
被导航到的页面的完整类如下:
namespace MyNotes
{
public partial class LocationDetails : PhoneApplicationPage
{
public LocationDetails()
{
InitializeComponent();
}
private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string filename = this.NavigationContext.QueryString["note"];
if (!string.IsNullOrEmpty(filename))
{
using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.ReadWrite, store))
{
StreamReader reader = new StreamReader(stream);
this.NoteTextBox.Text = reader.ReadToEnd();
this.FilenameTextBox.Text = filename; reader.Close();
}
}
base.OnNavigatedTo(e);
}
private void SaveButton_Click(object sender, EventArgs e)
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream(FilenameTextBox.Text, FileMode.Create, FileAccess.Write, store))
{
StreamWriter writer = new StreamWriter(stream);
writer.Write(NoteTextBox.Text); writer.Close();
}
}
catch (Exception)
{
MessageBox.Show("Error saving the file");
}
}
private void ListButton_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/LocationDetailsList.xaml", UriKind.Relative));
}
}
}
这是我导致崩溃的代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
/*
string filename = this.NavigationContext.QueryString["note"];
if (!string.IsNullOrEmpty(filename))
{
using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.ReadWrite, store))
{
StreamReader reader = new StreamReader(stream);
this.NoteTextBox.Text = reader.ReadToEnd();
this.FilenameTextBox.Text = filename; reader.Close();
}
}
*/
base.OnNavigatedTo(e);
}