有什么办法如何将属性从子控件传播到父 - 所以我可以访问属性,如 - Parent.Property1
而不是Parent.Child.Property1
?我不能使用继承 - 我的父母不能扩展子类型 - 它从不同的类继承。传播属性到父控制C#
而且我不想为每个属性添加代码,从孩子喜欢家长:
public object Property1
{
get{ return Child.Property1; }
set{ ChildProperty1 = value; }
}
也许使用反射 - 这样的事情?
public PropertyInfo[] Properties
{
get{ return Child.GetType().GetProperties(); }
set{ Child.GetType().GetProperties().SetValue() = value.GetValue()}
}
感谢
只需将属性添加到getters返回子属性的父类。这是正确的方法,你必须考虑它。太多?揭露孩子是不太合适的方式。 – 2012-03-24 11:19:50