我想将数据存储在下拉列表中以及2个单选按钮之间我必须使用Window phone 7中的隔离存储来存储一个值a a如何在Wp7中进行隔离存储?
在最容易做到这一点的方式,是使用IsolatedStorageSettings.ApplicationSettings类/属性-它是一个必须存活无论发生什么你所有的小的临时数据有很大DUMPBIN.通常,该对象会自动从ISO商店保存/恢复,但要小心相信 - 如果您的应用程序正常关闭,它就可以正常工作.如果你想防范这种情况,例如,应用程序崩溃/等等 - 你仍然应该定期手动调用此对象的SAVE.
一些链接/ tuts:MSDN:非常好的解释一个例子:http://msdn.microsoft.com/en-us/library/cc221360 (v = vs95).aspx来自google http:// dotnet的第一个. dzone.com/articles/using-application-settings
这是我用于在WP7应用程序中加载和保存高分的代码片段,根据您的需要进行调整.它可以挽救数百万人的生命:D
private void LoadHighScore()
{
// open isolated storage, and load data from the savefile if it exists.
#if WINDOWS_PHONE
using (IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication())
#else
using (IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain())
#endif
{
if (savegameStorage.FileExists("guessthecard.txt"))
{
using (IsolatedStorageFileStream fs = savegameStorage.OpenFile("guessthecard.txt", System.IO.FileMode.Open))
{
if (fs != null)
{
// Reload the saved high-score data.
byte[] saveBytes = new byte[4];
int count = fs.Read(saveBytes, 0, 4);
if (count > 0)
{
highScore = System.BitConverter.ToInt32(saveBytes, 0);
}
}
}
}
}
}
// Save highscore
public async void UnloadContent()
{
// SAVE HIGHSCORE
// Save the game state (in this case, the high score).
#if WINDOWS_PHONE
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
#else
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain();
#endif
// open isolated storage, and write the savefile.
IsolatedStorageFileStream fs = null;
using (fs = savegameStorage.CreateFile("guessthecard.txt"))
{
if (fs != null)
{
// just overwrite the existing info for this example.
byte[] bytes = System.BitConverter.GetBytes(highScore);
fs.Write(bytes, 0, bytes.Length);
}
}
try
{
CardGuess item = new CardGuess { Text = highScore.ToString() };
await App.MobileService.GetTable<CardGuess>().InsertAsync(item);
}
catch(Exception e)
{
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1170 次 |
| 最近记录: |