
[英]Store Combobox items in The Form of Array and Retrieve SelectedId in WPF
[英]Store and Retrieve user defined objects to IsolatedStorage in WPF (Devexpress) to display them in ComboBox
我有以下课程:
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));
}
}
}
我正在使用:
public ContentSet SelectedContentSet
{
get{return selectedContentSet;}
set{selectedContentSet = value;}
}
我正在使用此特定项目绑定以下ComboBox的SelectedItem:
<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>
因此,当返回以下值时:SelectedContentSet = //值该值绑定到ComboBox SelectedItem。
现在,一旦为ComboBox选择了一个值,我希望将该值存储在IsolatedStorage中,这样,即使我关闭了应用程序,在重新打开它时,我也可以检索保存的信息并再次显示它。
为了存储详细信息,我正在使用:
//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();
并取回它:
//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();
}
但是我无法检索这些值。 有关如何执行此操作的任何想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.