Windows Phone - 第一次如何设置 LocalSettings? [英] Windows Phone- How to set LocalSettings first time?

查看:23
本文介绍了Windows Phone - 第一次如何设置 LocalSettings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在桌面应用程序或 Web 项目项目中,有 App.configs 和 Web.configs 文件来存储设置.这些设置是在开发时(或稍后)设置的,但如果发生这种情况,则始终是一次操作.

In Desktop Application or Web Projects projects there were App.configs and Web.configs files to store settings. These settings were set in development time (or whenever later) but if this occures, it was ALWAYS once action.

在 Windows Phone 8.1 XAML 中没有任何 App.config 文件,因此开发人员可以使用 Windows.Storage.ApplicationData.Current.LocalSettings.好的.

In Windows Phone 8.1 XAML there isn't any App.config file, so developers are able to use Windows.Storage.ApplicationData.Current.LocalSettings. Nice.

我如何第一次设置这些设置(这意味着在第一次运行应用程序时,所以我以后只能读取它们并且有时更新现有值)?当然,我可以在运行应用程序时设置设置,但这很浪费时间.第一次如何在应用程序中设置 LocalSettings?我看到了这个解决方案 是否有第一次运行"?WP7 中的标志,但我不这么认为,这是唯一的可能性.

How can I set these settings first time (this means on first application run ever, so I can later only read them and sometimes update existing values)? Of course I can set settings whenever I run application but this is time wasting. How do you set LocalSettings in you applications first time? I saw this solution Is there a "first run" flag in WP7 but I don't think so, that this is the only possibility.

推荐答案

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

// Create a simple setting

localSettings.Values["exampleSetting"] = "Hello Windows";

// Read data from a simple setting

Object value = localSettings.Values["exampleSetting"];

if (value == null)
{
    // No data
}
else
{
    // Access data in value
}

// Delete a simple setting

localSettings.Values.Remove("exampleSetting");

Msdn 参考

数据持久化

这篇关于Windows Phone - 第一次如何设置 LocalSettings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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