我想創建一個繼承TriggerBase<FrameworkElement>
的特殊DataTrigger
。與DataTrigger
類似,MyDataTrigger
類中定義了BindingBase
類型的屬性。WPF如何聆聽BindingBase對象?
我怎樣才能聽到它的變化?
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
。
難道說,'BindingBase'相關DP總是'DataContext'? – Mimi 2013-04-09 06:23:57