2012-01-13 124 views
1

我想在metro風格的應用程序收到掛起事件時保存應用程序狀態。如何使用.net Metro風格應用程序的ApplicationStateModel類?

this link下面的代碼中發現的,但我不NET中找到類ApplicationStateModel:

public App() 
{ 
    InitializeComponent(); 
    this.Suspending += new SuspendingEventHandler(App_Suspending); 
    this.Resuming += new Windows.UI.Xaml.EventHandler(App_Resuming); 
} 

void App_Resuming(object sender, object e) 
{ 
    // Write code to update ui only for items that are outdated. 
    // This is resume from suspended state, so it does not lose any data 
} 

async void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) 
{ 
    // Write code to store data so that when the application is terminated the state can be recovered. 
    // Allowed only 5 seconds to do the storage 
    SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral(); 
    await **ApplicationStateModel**.SaveAllApplicationDataAsync(); 
    await ApplicationStateModel.SaveSessionStateAsync(); 
    deferral.Complete(); 
} 

回答

相關問題