Dan*_*ell 1 .net c# isolatedstorage windows-phone-7
我的WP7中有一个页面,其中包含一些文本框.按后退键时,运行此方法以保存内容:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["remZone"] = txtBoxZone.Text;
settings["remSpace"] = txtBoxSpace.Text;
}
Run Code Online (Sandbox Code Playgroud)
问题是有些用户不会按后退按钮,但会按主页按钮退出应用程序,因此内容不会保存.
我认为如果可能的话,有两种方法可以解决这个问题:1.当按下主页按钮时,是否存在运行此方法的函数,如onBackKeyPress.2.当用户输入文本框时,是否有一种简单的方法可以保存文本框的内容?
谢谢.
编辑:
解决方案是:
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["remZone"] = txtBoxZone.Text;
settings["remSpace"] = txtBoxSpace.Text;
}
Run Code Online (Sandbox Code Playgroud)