2014-06-21 13 views
0

IsolatedStorage에서 읽고 쓰는 사용자 지정 클래스가 있습니다. 내 모든 가치는 이미지를 제외하고 제대로 저장되고 검색되고 있습니다. 여기에 내가 PhotoChooserTask를 사용하여 이미지를 수집하고 저장 위치를 ​​IsolatedStorage 값을 저장하지 않음

다음
//Transparent Background 
public static readonly Setting<BitmapImage> TransparentBackground = new Setting<BitmapImage>("TransparentBackground", null); 

결과가

Settings.Page을 IsolatedStorage하는 것입니다 내 설치

Setting.cs

//Encapsulates a key/value pair stored in Isolated Storage ApplicationSettings 
public class Setting<T> 
{ 
    string name; 
    T value; 
    T defaultValue; 
    bool hasValue; 

    public Setting(string name, T defaultValue) 
    { 
     this.name = name; 
     this.defaultValue = defaultValue; 
    } 

    public T Value 
    { 
     get 
     { 
      //Check for the cached value 
      if (!this.hasValue) 
      { 
       //Try to get the value from Isolated Storage 
       if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue(this.name, out this.value)) 
       { 
        //It hasn't been set yet 
        this.value = this.defaultValue; 
        IsolatedStorageSettings.ApplicationSettings[this.name] = this.value; 
       } 
       this.hasValue = true; 
      } 
      return this.value; 
     } 

     set 
     { 
      //Save the value to Isolated Storage 
      IsolatedStorageSettings.ApplicationSettings[this.name] = value; 
      this.value = value; 
      this.hasValue = true; 
     } 
    } 

    public T DefaultValue 
    { 
     get { return this.defaultValue; } 
    } 

    // Clear cached value 
    public void ForceRefresh() 
    { 
     this.hasValue = false; 
    } 
} 

Settings.cs입니다 .xaml.cs

private void Browse_Click(object sender, RoutedEventArgs e) 
    { 
     photoChooserTask.Show(); 
    } 

    void photoChooserTask_Completed(object sender, PhotoResult e) 
    { 
     if (e.TaskResult == TaskResult.OK) 
     { 
      //Code to display the photo on the page in an image control named TransparentModeViewBoxImage. 
      BitmapImage bmp = new BitmapImage(); 
      bmp.SetSource(e.ChosenPhoto); 
      TransparentModeViewBoxImage.Source = Settings.TransparentBackground.Value = bmp; 
     } 
    }  

동일한 응용 프로그램 인스턴스에서 MainPage 배경을 Settings.TransparentBackground.Value으로 설정할 수 있습니다.이 응용 프로그램을 완전히 다시 시작하면 null이 반환되지만 Settings.TransparentBackground.Value null로 돌아갑니다. I에 폐쇄시

MainPage.xaml.cs를 응용 프로그램에서 아무데도

ImageBrush ib = new ImageBrush(); 

     if(Settings.TransparentBackground.Value == null) 
      //Use no background image 
     else 
      ib.ImageSource = Settings.TransparentBackground.Value; 

     LayoutRoot.Background = ib; 

null로 Settings.TransparentBackground.Value를 재설정합니다. 격리 된 저장소에이 값만 저장되지 않는 이유를 알 수 없습니다.

답변

1

IsolatedStorageSettings.ApplicationSettings 사전에 저장하려고합니다. 일반적으로 이것은 더 작은 데이터 조각, 더 중요한 것은 직렬화 할 수있는 데이터에 사용됩니다.

키 - 값 쌍은 고유 키 식별자 구성 및 해시 tables.IsolatedStorageSettings에서 발견 연관된 데이터 값을 저장하거나 키/값 쌍으로 데이터를 검색하는 데 사용되는 사전 클래스이다. 은 키와 함께이 사전에 모든 직렬화 가능 객체를 저장할 수 있습니다.

소스 - Quickstart: Working with settings for Windows Phone 8

그래서, 당신은 수동으로 BitmapImage를 저장해야합니다. this one과 같이 이미지를 로컬 저장소에 저장하는 것과 관련하여 여러 가지 더 오래된 질문을 참조하십시오.