Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# BindingList和嵌套属性_C#_Inotifypropertychanged_Nested_Bindinglist - Fatal编程技术网

C# BindingList和嵌套属性

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

我有一个跟踪视频流的类a,为了简单起见,我将类似属性的属性分组到一个子类中,使用自动属性来访问它们。然后我将整个类绑定到BindingList,但只显示None嵌套属性。如何使嵌套属性也显示出来

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");
       }
 }