【发布时间】:2016-04-18 08:19:55
【问题描述】:
但是尝试可能尝试过,我不知道如何序列化 (对不起。我在英语词典中找到了“What the hell” 这是坏话吗?无论如何我很抱歉)
- 当我使用 BinaryFormatter 时,它会从 RelayCommand 抛出异常(我想使用 XmlSerializer。我必须查看文件的文本)
我尝试使用 [XmlIgnore],但我认为它似乎不适用。 - 我在使用XmlSerializer的时候,不知道哪里会抛出异常。
- DataContractSerializer 抛出很多异常。所以我不想用。
请帮助我。 请理解,我不会说英语。
这是我的课。
扩展解决方案。
参考主要解决方案。
[Serializable]
public class SerializableContextBase : INotifyPropertyChanged
{
[field: NonSerialized()]
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string prop)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
}
主要解决方案
主要顶级类
[Serializable]
public class ResultContext : SerializableContextBase
{
public ResultContext() { }
private PerformanceContextCollection _PerformanceCollection = new PerformanceContextCollection();
public PerformanceContextCollection PerformanceCollection
{
get { return _PerformanceCollection; }
set
{
if (_PerformanceCollection == value) { return; }
_PerformanceCollection = value;
RaisePropertyChanged("PerformanceCollection");
}
}
底层类
[Serializable]
public class PerformanceContextCollection : ObservableCollection<PerformanceContext>
{
// some method
// public void Add(string Name){} ~~~
}
[Serializable]
public class PerformanceContext : SerializableContextBase
{
[XmlIgnore]
public RelayCommand<PerformanceContext> RemoveCommand { get; set; }
some string, some guid...~~
}
【问题讨论】:
标签: c# wpf serialization