The registration mechanism is non-intuitive. So I defined the following extension methods:
public static void AddDependencyPropertyChangedEventHandler(this DependencyObject obj, DependencyProperty dp, EventHandler handler) { var dpd = DependencyPropertyDescriptor.FromProperty(dp, obj.GetType()); dpd.AddValueChanged(obj, handler); } public static void RemoveDependencyPropertyChangedEventHandler(this DependencyProperty obj, DependencyProperty dp, EventHandler handler) { var dpd = DependencyPropertyDescriptor.FromProperty(dp, obj.GetType()); dpd.RemoveValueChanged(obj, handler); }
No comments:
Post a Comment