Check for pending changes when using WPF explicit binding

I have a modal pop-up window that contains a Check@R_955_2419 @, when the user clicks the Save button on the form, it uses explicit binding to update the binding source

<Check@R_955_2419@ Content="Default" IsChecked="{Binding Path=Unit.IsDefault,Mode=TwoWay,UpdateSourceTrigger=Explicit"/>

Now I want to add a cancel button to the form. If the user clicks it, I want to check whether there are any pending binding updates. If so, a message will be displayed to the user

May this be related to binding? I want something similar:

BindingExpression binding = cb.GetBindingExpression(Check@R_955_2419@.IsCheckedProperty);
binding.HasPendingUpdates(); // Anything similar to this?

If not, does anyone have any other suggestions on how to track changes to bindings that have not been explicitly updated?

Solution

As Kurian points out, if you use a Net 4.5, you can use the attribute isdirty on bindingexpressionbase

At the same time, the solution may be to use reflection to check the internal property needsupdate:

public static bool IsDirty(this BindingExpression binding)
{
    if (binding == null)
        throw new ArgumentNullException("binding");

    var needsUpdateProperty = typeof(BindingExpressionBase).GetProperty("NeedsUpdate",BindingFlags.Instance | BindingFlags.NonPublic);
    var isDirtyAsObject = needsUpdateProperty.GetValue(binding,null);
    if (isDirtyAsObject is bool)
        return (bool)isDirtyAsObject;

    return false;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>