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

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

问题描述

在桌面应用程序或Web项目项目有App.configs和Web.configs文件存储设置。这些设置是在开发时间(或每当更高版本)设置,但如果这occures,它总是一次行动。



在Windows Phone的8.1 ​​XAML没有任何应用程序。配置文件,使开发人员能够使用 Windows.Storage.ApplicationData.Current.LocalSettings 。尼斯。



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


解决方案

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

//创建一个简单的设置

localSettings.Values​​ [exampleSetting] =你好窗口;

//从简单的设置

对象值= localSettings.Values​​ [exampleSetting]读取数据;

如果(价值== NULL)
{
//没有数据
}
,否则
{
//访问价值
数据}

//删除一个简单的设置

localSettings.Values​​.Remove(exampleSetting);

参考MSDN



持久性数据的


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.

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.

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 Reference

Persistance of Data

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

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