C# 是否可以使用属性进行分层数据绑定?
是否可以绑定到属性的属性? 以下是我所拥有的:C# 是否可以使用属性进行分层数据绑定?,c#,winforms,data-binding,properties,C#,Winforms,Data Binding,Properties,是否可以绑定到属性的属性? 以下是我所拥有的: [Bindable(true)] public class DataClass { private string DescriptionValue = null; private Content DataContent Value = new Content(); .... [Bindable(true)] public Content Dat
[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类中引入映射内容类属性的属性。我只是想知道是否可以使用属性进行分层数据绑定。您正在做什么类型的数据绑定 使用简单绑定(
TextBox.Text
到单个对象),可以使用“Foo.Bar.SomeProp”作为成员。对于PropertyGrid
,您可以使用[TypeConverter(typeof(ExpandableObjectConverter))]
标记对象,它将起作用
棘手的是列表绑定(DataGridView
etc);这里,不:它不容易变平。如果转到greatlength(ITypedList
等),您可以这样做,但这确实不值得-只需将垫片属性添加到父项:
public string ChildName {
get {return child == null ? "" : child.Name;} // and setter if you want
}
您正在执行什么类型的数据绑定 使用简单绑定(
TextBox.Text
到单个对象),可以使用“Foo.Bar.SomeProp”作为成员。对于PropertyGrid
,您可以使用[TypeConverter(typeof(ExpandableObjectConverter))]
标记对象,它将起作用
棘手的是列表绑定(DataGridView
etc);这里,不:它不容易变平。如果转到greatlength(ITypedList
等),您可以这样做,但这确实不值得-只需将垫片属性添加到父项:
public string ChildName {
get {return child == null ? "" : child.Name;} // and setter if you want
}