我想创建一个特殊DataTrigger
的继承TriggerBase<FrameworkElement>
. 与 类似,在类中定义了DataTrigger
一个类型的属性。BindingBase
MyDataTrigger
我怎样才能听它以追踪它的变化?
public class MyDataTrigger : TriggerBase<FrameworkElement>
{
...
/// <summary>
/// [Wrapper property for BindingProperty]
/// <para>
/// Gets or sets the binding that produces the property value of the data object.
/// </para>
/// </summary>
public BindingBase Binding
{
get { return (BindingBase)GetValue(BindingProperty); }
set { SetValue(BindingProperty, value); }
}
public static readonly DependencyProperty BindingProperty =
DependencyProperty.Register("Binding",
typeof(BindingBase),
typeof(MyDataTrigger),
new FrameworkPropertyMetadata(null));
}
更新:
主要问题是我不知道如何找到BindingBase
关联的DependencyProperty
. 我知道如何听 DP;
void ListenToDP(object component, DependencyProperty dp)
{
DependencyPropertyDescriptor dpDescriptor = DependencyPropertyDescriptor.FromProperty(dp, component.GetType());
dpDescriptor.AddValueChanged(component, DPListener_ValueChanged);
}
DPListener_ValueChanged
代表在哪里EventHandler
。这里,组件参数值为this.AssociatedObject
。