当前位置:编程学习 > wap >>

Windows Phone7生命周期与永久数据和临时数据的保存

一般生命周期\

 然而任何使用应用程都可以能发生中断, 用户的操作  ,外部的事件 ,所以下面的场景也是很常见的:\


 

从图上可以看到,有这么几个事件是非常重要的:

    App.xaml.cs:Application_Launching 
  
    App.xaml.cs:Application_Closing
  
    App.xaml.cs:Application_Deactivated
  
    App.xaml.cs:Application_Activated
  这几个事件都是定义在App.xmal.cs文件里:

 \


 

在这些事件里面 我们可以选择性的保存程序的数据,除了这四个意外还有另外两个页面级别的事件:

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
  {
      base.OnNavigatedFrom(e);
       App.Persistdata  = textBox1.Text;
       App.tempdata = textBox2.Text;
       State["页面数据"] = textBox3.Text;
  }
  protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  {
      base.OnNavigatedTo(e);
      if (App.Persistdata != null)
      {
          textBox1.Text = App.Persistdata;
      }
      if (App.tempdata != null)
      {
          textBox2.Text = App.tempdata;
      }
      if (State.ContainsKey("页面数据"))
      {
 
          textBox3.Text = State["页面数据"] as string ;
      }
   
  }
 
 总结:
• 对于永久性的数据,我们使用IsolatedStorageSettings.ApplicationSettings来保存
• 对于临时数据我们可以保存在  PhoneApplicationService.Current.State或者PhoneApplicationPage的属性State里
 

摘自 麻将我会
补充:移动开发 , Windows Phone ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,