2009-06-30 15 views
1

プロパティのプロパティにバインドすることはできますか?ここ は、私が持っているものです。プロパティを持つ階層的なデータバインディングが可能ですか?

[Bindable(true)] 
    public class DataClass 
    { 
     private string DescriptionValue = null; 
     private Content DataContent Value = new Content(); 
     .... 

     [Bindable(true)] 
     public Content DataContent 
     { 
      get { return DataContent; } 
      set { DataContent = value; } 
     } 

     [Bindable(true)] 
     public string Description 
     { 
      get { return DescriptionValue; } 
      set { DescriptionValue = value; } 
     } 
     ... 
    } 


    [Bindable(true)] 
    public class Content 
    { 
     private object ContentValue = null; 
     private Color StateBackColorValue; 
     ... 

     [Bindable(true)] 
     public object Content 
     { 
      get { return ContentValue; } 
      set { ContentValue = value; } 
     } 

     [Bindable(true)] 
     public Color StateBackColor 
     { 
      get { return StateBackColorValue; } 
      set { StateBackColorValue = value; } 
     } 
     ... 
    } 

はDataContent.Contentにコントロールまたはコンテンツクラスの他のプロパティをバインドすることが何とか可能ですか?私はContentクラスのプロパティをマップするDataContentクラスのプロパティを導入できることを知っています。私は、プロパティを持つ階層的なデータバインディングが可能かどうかを知りたかっただけです。

答えて

1

どのような種類のデータバインディングを実行していますか?

単純バインディング(たとえば、単一のオブジェクトに対してTextBox.Text)を使用すると、「Foo.Bar.SomeProp」をメンバーとして使用できます。 PropertyGridの場合は、オブジェクトに[TypeConverter(typeof(ExpandableObjectConverter))]とマークすると動作します。

トリッキーなのはリストバインディング(DataGridViewなど)です。ここでは、それは簡単に平らにならない。あなたは偉大長(ITypedListなど)に行けば、あなたはそれを行うことができますが、本当に価値がない - ちょうど親にシムプロパティを追加します。

public string ChildName { 
    get {return child == null ? "" : child.Name;} // and setter if you want 
} 
関連する問題