DependencyProperty doesn't fire ValueChanged when new value is the same DependencyProperty doesn't fire ValueChanged when new value is the same wpf wpf

DependencyProperty doesn't fire ValueChanged when new value is the same


You can wrap your value up in an object, i.e. create a class to hold it - then set the property to a new instance of that class containing the new value, every time. That means you're creating ~10 objects per second, but they are each different, will trigger the change event, and are only small (will be GC'd anyway). :)


Another alternative is to switch the value temporarily to something else then restore the previous one. You can do this entire trick transparently in the Coerce callback as such:

public static readonly DependencyProperty TestProperty = DependencyProperty.Register(    "Test", typeof(object), typeof(School),    new PropertyMetadata(null, TestChangedCallback, TestCoerceCallback));static object TestCoerceCallback(DependencyObject d, object baseValue){    if (baseValue != null && (d.GetValue(TestProperty) == baseValue))    {        d.SetCurrentValue(TestProperty, null);        d.SetCurrentValue(TestProperty, baseValue);    }    return baseValue;}

Just make sure your property code can handle the null value case gracefully.