我认为您可以选择 IExtenderProvider。ExtenderProvider 将属性添加到它可以扩展的控件。你可以在这里找到一个例子:
http://msdn.microsoft.com/en-us/library/system.componentmodel.iextenderprovider.aspx
enum AttachDirection { Right, Left, None }
[ProvideProperty("IsRequired", typeof(Control))]
class MyControl : UserControl, IExtenderProvider
{
MyControl Left { get; set; }
MyControl Right { get; set; }
public bool CanExtend(object extendee)
{
if (extendee is MyControl)
return true;
return false;
}
public void SetAttachTo (Control ctrl, AttachDirection direction)
{
if(direction == AttachDirection.Right)
this.setRight(ctrl);
else if (direction == AttachDirection.Left)
this.setLeft(ctrl);
}
//And so on ...
}