0

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

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

2 回答 2

1

您需要触发OnPropertyChanged父类型,而不是子类型。

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

Stream将其放入构造函数中SubCodec并且不允许更改它可能更简单。这将是避免我在Codecset 方法的注释中提到的问题的一种方法。

于 2013-01-18T16:47:02.340 回答
0

您需要PropertyChangedSubCodec

private SubCoded _codec;
internal SubCodec Codec 
{
      get {return _codec;}  
      set 
      {
            _codec = value;
            OnPropertyChanged("Codec");
       }
 }
于 2013-01-18T16:47:25.140 回答