I have the following Class:
public partial class ContentSet{
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.Nullable<int> IdField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string NameField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Nullable<int> Id {
get {
return this.IdField;
}
set {
if ((this.IdField.Equals(value) != true)) {
this.IdField = value;
this.RaisePropertyChanged("Id");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Name {
get {
return this.NameField;
}
set {
if ((object.ReferenceEquals(this.NameField, value) != true)) {
this.NameField = value;
this.RaisePropertyChanged("Name");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
Which, I am using :
public ContentSet SelectedContentSet
{
get{return selectedContentSet;}
set{selectedContentSet = value;}
}
This particular Item, I am using to bind the SelectedItem for the below ComboBox:
<dxe:ComboBoxEdit x:Name="ContentSetCombobox" Grid.Column="1" Height="25" IncrementalFiltering="True" ItemsSource="{Binding ContentSetList}" DisplayMember="Name" AllowUpdateTwoWayBoundPropertiesOnSynchronization="False" SelectedItem="{Binding SelectedContentSet,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<dxe:ComboBoxEdit.StyleSettings>
<dxe:ComboBoxStyleSettings/>
</dxe:ComboBoxEdit.StyleSettings>
</dxe:ComboBoxEdit>
So, when a value is returned for: SelectedContentSet = //Value That value is bound to the ComboBox SelectedItem.
Now, once a value is selected for the ComboBox, I want that value to be stored in a IsolatedStorage so that even if I close the application, upon reopening it, I can retrieve the saved information and display it again.
For storing the details, I am using:
//First Get the 'User-Scoped' storage information location reference in the assembly
IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetMachineStoreForAssembly();
//Create a stream writer object to write content in the location
StreamWriter srWriter = new StreamWriter(new IsolatedStorageFileStream("isotest", FileMode.Create, isolatedStorage));
//check if the Application property collection contains any values
if (App.Current.Properties[0] != null)
{
srWriter.Write(save);
}
srWriter.Flush();
srWriter.Close();
And for retrieving it back:
//First get the 'User-Scoped' storage information location refernce in the assembly
IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetMachineStoreForAssembly();
//Create a stream reader object to read content from the created isolation location
StreamReader srReader = new StreamReader(new IsolatedStorageFileStream("isotest", FileMode.OpenOrCreate, isolatedStorage));
{//Open the Isolated Storage
if (srReader==null)
{
MessageBox.Show("No Data Stored");
}
else
{
while(!srReader.EndOfStream)
{
App.Current.Properties[0] = srReader.ReadLine();
}
}
srReader.Close();
}
But I was unable to retrieve the values. Any ideas on how to do this?