验证 Windows Phone 应用程序的独立存储中的应用程序设置键值
我对 C# Windows Phone 编程非常陌生,所以这很可能是一个愚蠢的问题,但我需要知道任何人......
IsolatedStorageSettings appSettings =
IsolatedStorageSettings.ApplicationSettings;
if (!appSettings.Contains("isFirstRun"))
{
firstrunCheckBox.Opacity = 0.5;
MessageBox.Show("isFirstRun not found - creating as true");
appSettings.Add("isFirstRun", "true");
appSettings.Save();
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = true;
}
else
{
if (appSettings["isFirstRun"] == "true")
{
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = true;
}
else if (appSettings["isFirstRun"] == "false")
{
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = false;
}
else
{
firstrunCheckBox.Opacity = 0.5;
}
}
我试图首先检查我的应用程序设置隔离存储中是否有特定的密钥,并且然后希望使复选框显示为选中或未选中,具体取决于该键的值是“true”还是“false”。另外,当不对其采取任何操作时,我将复选框的不透明度默认为 0.5。
使用我拥有的代码,我收到警告
可能是意外的参考比较;要进行值比较,请将左侧转换为“字符串”
有人可以告诉我我做错了什么吗?我已经尝试过将数据存储在独立存储 txt 文件中,这很有效,我现在正在尝试应用程序设置,最后将尝试下载并存储 xml 文件,以及创建用户设置并将其存储到 xml 文件中。我想尝试了解所有向我开放的选项,并使用运行得更好更快的选项
I am very new at all this c# Windows Phone programming, so this is most probably a dumb question, but I need to know anywho...
IsolatedStorageSettings appSettings =
IsolatedStorageSettings.ApplicationSettings;
if (!appSettings.Contains("isFirstRun"))
{
firstrunCheckBox.Opacity = 0.5;
MessageBox.Show("isFirstRun not found - creating as true");
appSettings.Add("isFirstRun", "true");
appSettings.Save();
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = true;
}
else
{
if (appSettings["isFirstRun"] == "true")
{
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = true;
}
else if (appSettings["isFirstRun"] == "false")
{
firstrunCheckBox.Opacity = 1;
firstrunCheckBox.IsChecked = false;
}
else
{
firstrunCheckBox.Opacity = 0.5;
}
}
I am trying to firstly check if there is a specific key in my Application Settings Isolated Storage, and then wish to make a CheckBox appear checked or unchecked depending on if the value for that key is "true" or "false". Also I am defaulting the opacity of the checkbox to 0.5 opacity when no action is taken upon it.
With the code I have, I get the warnings
Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
Can someone tell me what I am doing wrong. I have explored storing data in an Isolated Storage txt file, and that worked, I am now trying Application Settings, and will finally try to download and store an xml file, as well as create and store user settings into an xml file. I want to try understand all the options open to me, and use which ever runs better and quicker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您显式地将 appSettings 中的值检索结果转换为如下字符串:
这将使警告消失。
If you explicitly cast the results of the value retrieval from the appSettings to string like this:
and that will make the warnings go away.
isolatedStorageSettings 存储为字典。因此,一般来说,您需要将其显式转换为您需要使用的任何类型。
IsolatedStorageSettings are stored as Dictionary. So in general you would need to cast it explicitly to whatever type you need to use.