2013-01-18 124 views
0

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

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

回答

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

这可能是简单的把StreamSubCodec构造函数,而不是让它来改变。这将是避免我在Codec设置方法的评论中提到的问题的一种方法。

0

您需要在提高PropertyChanged事件SubCodec

private SubCoded _codec; 
internal SubCodec Codec 
{ 
     get {return _codec;} 
     set 
     { 
      _codec = value; 
      OnPropertyChanged("Codec"); 
     } 
}