假設你有一個包含名爲DateToDisplayAsToday
日期時間字段的模型類,並且該模式中的App.xaml訪問,你會想要在App.xaml.cs中的以下內容
private void Application_Launching(object sender, LaunchingEventArgs e)
{
// Application_Launching fires when the app starts up.
// retrieve any data you persisted the last time the app exited.
// Assumes you have a local instance of your model class called model.
model = new model();
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Application_Activated fires when you return to the foreground.
// retrieve any data you persisted in the Application_Deactivated
// and then you can set the current DateTime
model.DateToDisplayAsToday = DateTime.Now;
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
// persist an data you don't want to lose during tombstoning
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
// persist any data you want to keep between separate executions of the app
}
顯然,我發現,即使通過更改時區,它不會得到反應時,應用程序重新激活。我檢查了TimeZoneInfo.local。它甚至在更改後仍保持同一時間。 :( – alfah