2012-06-06 4 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 


     } 

는 사용자가 버튼을 다시 응용 프로그램에 로그인 사용자가 사용자 때문에 unchcked을 보여줄 필요가 unchcked method.If을 확인 이전에 btn을 unchcked.vut 그것은 격리 된 스토리지에 하나의 값을 저장하고있다. 격리 된 가변 값에 액세스 할 수있는 위치를 알려주십시오.

답변

1

작성한 것과 같은 방법으로 모든 페이지에서 격리 보관 값에 액세스 할 수 있습니다.

InitializeComponent(); 값 뒤에 Settings() 생성자의 값에 액세스하려고합니다.

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

다음 '값'을 토글 버튼의 ​​값을 변경할 수 있습니다.

1

ApplicationSettings 개체에서 Save 메서드를 호출하지 않는 것으로 보입니다.
격리 된 저장소로 작업하는 방법에 대해서는 this guide을 읽으십시오. , 귀하의 경우 그래서

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

위탁 & 선택하지 않은 경우에 체크 박스 상태를 저장하고 상태를로드

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

이 설정을 검색하려면 :

는 설정을 저장하려면 페이지 초기화

관련 문제