0
  public IsolatedStorageSettings appSettings =
                  IsolatedStorageSettings.ApplicationSettings;


public Settings()
        {
            InitializeComponent();
             this.toggle.Checked += new EventHandler<RoutedEventArgs>(toggle_Checked);
             this.toggle.Unchecked += new EventHandler<RoutedEventArgs>(toggle_Unchecked);


 this.toggle.Click += new EventHandler<RoutedEventArgs>(toggle_Click);
            this.toggle.Indeterminate += new EventHandler<RoutedEventArgs>(toggle_Indeterminate);
    `}`

void toggle_Unchecked(对象发送者,RoutedEventArgs e){

            this.toggle.Content = "Visibity is off";
            this.toggle.SwitchForeground = new SolidColorBrush(Colors.Red);
            appSettings.Add("value", "off");
        }

        void toggle_Checked(object sender, RoutedEventArgs e)
        {


            this.toggle.Content = "Visibity is on";
            this.toggle.SwitchForeground = new SolidColorBrush(Colors.Green);
            appSettings.Add("value", "on");
        }

        void toggle_Indeterminate(object sender, RoutedEventArgs e)
        {
            //add some content here
        }

        void toggle_Click(object sender, RoutedEventArgs e)
        {
            //add some content here


        }

默认情况下调用检查方法。如果用户取消选中按钮,那么再次登录应用程序的用户需要显示未选中,因为用户之前取消了 btn。但它显示已选中。因为我将一个值保存在隔离存储中。你能告诉我在哪里访问隔离变量值吗?

4

2 回答 2

1

您似乎没有Save在 ApplicationSettings 对象上调用该方法。
请阅读本指南,了解如何使用隔离存储。

要保存设置:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("userData"))
{
settings.Add("userData", "some value");
}
else
{
settings["userData"] = "some value";
}
settings.Save();

要检索设置:

if (IsolatedStorageSettings.ApplicationSettings.Contains("userData"))
{
 string result  IsolatedStorageSettings.ApplicationSettings["userData"] as string;
}

因此,在您的情况下,将 CheckBox 的状态保存在 Checked & UnChecked 事件中,并在页面的 init 中加载状态。

于 2012-06-06T06:10:29.067 回答
1

您可以访问任何页面中的 isolatedstorage 值,方法与创建它的方式相同。

尝试在 InitializeComponent() 之后访问 Settings() 构造函数中的值;

public Settings()
    {
        InitializeComponent();
        string value;
        if (appSettings.Contains("value"))
        {
            appSettings.TryGetValue("value", out value);
        }

然后您可以根据“值”更改切换按钮的值。

于 2012-06-06T06:11:43.490 回答