As mentioned in this question, there are at least two ways by which I can be notified that the value bound to a dependency property has changed:
- DependencyPropertyDescriptor.AddValueChanged
- DependencyProperty.OverrideMetadata on a derived class with my own PropertyChangedCallback.
This is all working fine but I need to be notif开发者_Python百科ied only when the actual binding is set on the property not every time the value changes. Is there a way to register a callback for this or an event I need to listen to?
I have looked in MSDN on the classes DependencyProperty, DependencyObject, BindingOperations and DependencyPropertyDescriptor.
I don't think there is an "official way" to do that, although I had the same problem some days ago and came up with a quite stupid but at least efficient workaround
private bool isSet = false;
public static readonly DependencyProperty DummyProperty =
DependencyProperty.Register("DummySource",
typeof(DummyType),
typeof(WhateverYouWant),
new PropertyMetadata((s, a) =>
{
if (!isSet)
{
//Blah blah about what you wanna do
isSet = true
}
}));
Works fine for me, should do the trick for you as well :)
精彩评论