在 Windows 手机上存储数据 [英] Storing data on Windows phone

查看:21
本文介绍了在 Windows 手机上存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序将存储用户添加的一些收藏信息.我想为每个收藏存储两条信息 - 一个数字和一段文本.所以它会是这样的:

I'm working on an app that is going to store some favourites information that the user has added. I want to store two pieces of information for each favourite - a number and a piece of text. So it will be something like this:

123 Some text
1234 Some more text
1233 More text

等等.

该数字将是唯一的,因此用作密钥应该没问题,无论如何我都需要将此数字单独存储,以便使用它来查询某些数据.

The number will be unique so it should be fine to use as a key and I will need to have this number stored separately anyway in order to use it to query some data.

在 Windows Phone 上存储这些数据的最佳方式是什么?我一直在查看isolatedStorage,特别是ApplicationSettings,但是我认为它一次只存储一条信息?至少当我添加一些收藏夹信息时,原始值被新值覆盖.

What is the best way to store this data on Windows Phone? I've been looking at IsolatedStorage and specifically, ApplicationSettings however I think it only stores one piece of information at a time? At least when I added some favourites information, the original value got overwritten by the new value.

我是否需要使用某种数据库将这些信息存储在 IndependentStorage 中?我无法想象数据量会很大.我希望用户最多只能添加一些收藏夹.

Do I need to use some sort of database to store this information in IsolatedStorage? I can't imagine the amount of data will be huge. I would expect the users may only add a handful of favourites at most.

在 Windows Phone 上存储一些采用键和值形式的数据的最佳方法是什么?一旦用户添加了他们的收藏夹信息,则需要在加载应用程序时自动存储和加载这些信息.

What's the best way to go about storing some data that takes the form of a key and a value on Windows Phone? Once the user has added their favourites information, it will need to be stored and loaded automatically when the app is loaded.

推荐答案

一个非常简单的解决方案是使用 IndependentStorageSettings.设置是一个值字典.您可以访问此类设置

A very simple solution is to use the IsolatedStorageSettings. The settings is a dictionary of values. You access settings like such

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

bool useLocation;
if (settings.TryGetValue("UseLocation", out useLocation) == false)
{
    // provide a default value if the key does not exist
    useLocation = true;
}

然后您可以像这样保存设置

You then can save settings like such

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

settings["UseLocation"] = value;
settings.Save();

更好的是创建一个不错的 Settings 类来为您处理所有这些.这是一个不错的博客 详细说明如何做到这一点的帖子.

Even better is to create a nice Settings class to take care of all of that for you. Here is a nice blog post detailing how to do that.

这篇关于在 Windows 手机上存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆