C# BindingList和嵌套属性
我有一个跟踪视频流的类a,为了简单起见,我将类似属性的属性分组到一个子类中,使用自动属性来访问它们。然后我将整个类绑定到BindingList,但只显示None嵌套属性。如何使嵌套属性也显示出来C# BindingList和嵌套属性,c#,inotifypropertychanged,nested,bindinglist,C#,Inotifypropertychanged,Nested,Bindinglist,我有一个跟踪视频流的类a,为了简单起见,我将类似属性的属性分组到一个子类中,使用自动属性来访问它们。然后我将整个类绑定到BindingList,但只显示None嵌套属性。如何使嵌套属性也显示出来 public class Stream: : INotifyPropertyChanged { public bool InUse { get { return _inUse; } set { _inUse = value; OnPropertyChan
public class Stream: : INotifyPropertyChanged
{
public bool InUse {
get { return _inUse; }
set {
_inUse = value;
OnPropertyChanged("InUse");
}
}
}
....
internal SubCodec Codec { get; set; }
internal class SubCodec
{
public string VideoCodec
{
get { return _audioCodec; }
set {
_audioCodec = value;
OnPropertyChanged("AudioCodec");
}
}
....
}
您需要在父类型的PropertyChanged上激发
,而不是在子类型上激发
public class Stream : INotifyPropertyChanged
{
private SubCodec _codec;
internal SubCodec Codec
{
get
{
return _codec;
}
set
{
_codec = value;
//note that you'll have problems if this code is set to other parents,
//or is removed from this object and then modified
_codec.Parent = this;
}
}
internal class SubCodec
{
internal Stream Parent { get; set; }
private string _audioCodec;
public string VideoCodec
{
get { return _audioCodec; }
set
{
_audioCodec = value;
Parent.OnPropertyChanged("VideoCodec");
}
}
}
}
将流
放入子代码
的构造函数中,并且不允许对其进行更改,可能会更简单。这将是避免我在编解码器
设置方法的注释中提到的问题的一种方法。您需要在子代码
上引发属性更改
事件
private SubCoded _codec;
internal SubCodec Codec
{
get {return _codec;}
set
{
_codec = value;
OnPropertyChanged("Codec");
}
}