1、进入页面时
OnNavigatedTo-Loaded
2、离开页面时
OnNavigationFrom
OnNavigatedFrom
UnLoaded
总结:
OnNavigatedTo→ Loaded→ OnNavigationFrom→ OnNavigatedFrom→ UnLoaded
后台代码:
public partial class About : PhoneApplicationPage
{
public About()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(About_Loaded);
this.Unloaded += new RoutedEventHandler(About_Unloaded);
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
MessageBox.Show("我是OnNavigatedFrom");
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
MessageBox.Show("我是OnNavigatedTo");
}
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
MessageBox.Show("我是OnNavigatingFrom");
}
void About_Unloaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("我是About_Unloaded");
}
void About_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("我是loaded");
//throw new NotImplementedException();
}
}