DependencyObject.InvalidateProperty not working

后端 未结 3 2008
暖寄归人
暖寄归人 2021-01-11 12:16

Based on the documentation via MSDN...

You can also use InvalidateProperty to force re-evaluation of a binding against a data source that is not a

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-11 12:49

    As you mentioned, it ought to work but doesn't. But there is a simple workaround:

    // Doesn't work:
    //b.InvalidateProperty(Button.ContentProperty);
    
    // Works:
    BindingOperations.GetBindingExpression(b, Button.ContentProperty).UpdateTarget();
    

    I debugged into the reference source and all InvalidateProperty does in your situation is cause a cached value to be re-read from the BindingExpression into the Button Content property. Offhand, I don't know when this would even be necessary but it's not useful to get the BindingExpression to re-read the raw property.

    Since the workaround is convenient and general, the only further effort warranted is filing a bug report with Microsoft.

提交回复
热议问题