2013-01-18 127 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"); 
     } 
}