比方说,我有一个自定义控件包装另一个控件(例如MyCustomButton)。我露出一个属性的内容,它包装内部控制:链接依赖属性
public object Content
{
get { return innerControl.Content; }
set { innerControl.Content = value; }
}
为了让消费者绑定到这个属性,我需要定义一个DependencyProperty吧:
public static DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof (object), typeof (MyCustomButton));
但现在我需要我的属性定义使用的GetValue /的SetValue:
所以我不包装内部控制的价值了。
我可以定义PropertyMetadata来处理DependencyProperty的PropertyChanged事件,但后来我需要一堆管道代码来保持这些值同步并防止发生无限循环更改。
更新:我不能从按钮派生,因为我的UserControl有其他各种问题。
有没有更好的方法来做到这一点?
用户控件还有其他问题。更新的问题。 – Jeff 2011-12-14 19:49:35