2

我对所有这些 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”,使 CheckBox 显示为选中或未选中。此外,当未对其采取任何操作时,我将复选框的不透明度默认为 0.5 不透明度。

使用我拥有的代码,我收到警告

可能的意外参考比较;要进行值比较,请将左侧转换为“字符串”

有人可以告诉我我做错了什么。我已经探索了将数据存储在独立存储 txt 文件中,并且可行,我现在正在尝试应用程序设置,最终将尝试下载和存储 xml 文件,以及创建用户设置并将其存储到 xml 文件中。我想尝试了解所有对我开放的选项,并使用运行得更好更快的选项

4

2 回答 2

3

如果您将 appSettings 中的值检索结果显式转换为字符串,如下所示:

        if ((string)appSettings["isFirstRun"] == "true")
        {
            firstrunCheckBox.Opacity = 1;
            firstrunCheckBox.IsChecked = true;
        }
        else if ((string)appSettings["isFirstRun"] == "false")
        {
            firstrunCheckBox.Opacity = 1;
            firstrunCheckBox.IsChecked = false;
        }
        else
        {
            firstrunCheckBox.Opacity = 0.5;
        }

这将使警告消失。

于 2010-03-23T02:25:51.177 回答
1

隔离存储设置存储为字典。因此,通常您需要将其显式转换为您需要使用的任何类型。

于 2010-04-04T09:20:55.477 回答