在第二个页面中:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
NoteListBox.ItemsSource = Text.FileNames;
base.OnNavigatedTo(e);
}
其中 NoteListBox.ItemsSource = Text.FileNames;是ListBox中Link控件的Content属性绑定到Text类的静态属性FileNames(List<string>类型)。FileNames属性会在第三个页面中的删除操作而从List中删除;
在第三个页面中:
Text.FileNames.Remove(title);
if (NavigationService.CanGoBack)
//NavigationService.Navigate(new Uri("/ListPage.xaml",UriKind.Relative));
NavigationService.GoBack();
我想实现的是当调用 NavigationService.GoBack();时返回第二个页面,并会发现被删除的那个title已经不存在了。但问题是当调用 NavigationService.GoBack();时,先执行了第二个页面的OnNavigatedTo()方法。执行完后就直接退出了,在Application_Closing设置断点,也没见调用~~
另外,当不调用第三个页面的Text.FileNames.Remove(title); 即不删除List中的内容,返回时正常。