Wp8程序加载运行顺序(菜鸟篇)

第一次加载程序:

This is App
This is Application_Launching
This is MainPage()
This is OnNavigatedTo
This is MainPage_Loaded()

返回键离开:

This is OnNavigatingFrom
This is OnNavigatedFrom
This is Application_Closing
This is ~MainPage()

Home键离开:

This is OnNavigatingFrom
This is OnNavigatedFrom
This is Application_Deactivated

Home键离开后启动:

This is Application_Activated
This is OnNavigatedTo

以上就是WP8程序开启离开的常用事件运行顺序,仅供像我一样的菜鸟学习;

扩展:上面顺序就可以很好解释下面(为什么NavigationContext在构造函数写的话会出现NullReference):

发送页面发送字符串:

NavigationService.Navigate(new  Uri("/Page.2xaml?msg=" + textBox1.Text, 
 
UriKind.Relative)); 
复制代码
接受页面接受字符串:
protected override void OnNavigatedTo( 
System.Windows.Navigation.NavigationEventArgs e) 
{ 
  base.OnNavigatedTo(e); 

  string msg = string.Empty; 

  if (NavigationContext.QueryString.TryGetValue("msg", out msg)) 
  {
    textBlock1.Text = msg
  }

}
复制代码

 原文地址:http://www.cnblogs.com/Yukang1989/archive/2012/11/22/2783121.html

posted on 2013-01-29 11:16  Frank.Cui  阅读(324)  评论(0编辑  收藏  举报