2012-06-06 42 views
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); 
    `}` 

空隙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 


     } 

默認主叫檢查method.If用戶unchcked按鈕然後再次登錄的應用的用戶需要顯示unchcked因爲用戶以前unchcked btn.but它顯示checked.for,我在孤立存儲節省一個值。 你能告訴我在哪裏訪問孤立的varieable值?

回答

1

您可以像創建它一樣訪問任何頁面中的isolatedstorage值。

嘗試訪問InitializeComponent()後的Settings()構造函數中的值;

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

然後您可以根據'值'更改切換按鈕的值。

1

看起來你並沒有調用ApplicationSettings對象的Save方法。
請閱讀this guide關於如何使用獨立存儲的問題。

要保存設置:

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; 
} 

所以你的情況,保存在經過&未檢查的事件的複選框的狀態,並加載狀態在頁面的init中。