c# - Notify when the binding of Dependency Property is changed -
i need debug binding setup of given dependency property. @ beginning, set binding dependency property given source instance, following code:
var binding = new binding(path); binding.source = source; binding.mode = twoway ? bindingmode.twoway : bindingmode.oneway; binding.updatesourcetrigger = updatesourcetrigger.propertychanged; binding.converter = valueconverter; var bindingresult = bindingoperations.setbinding(this, modelvalueproperty, binding); var bindingexpression = bindingoperations.getbindingexpression(this, modelvalueproperty);
bindingexpression not null , status of binding active. after view manipulations, when try bindingexpression null. how catch binding replacement or change on given dependency property ?
edit: in way, want know how notified when bindingexpression changes status active detached
you need set property:
binding.notifyonsourceupdated = true
and register sourceupdated
event of control you're bound (in case, it's this
):
this.sourceupdated += (s, args) => { // catch changes there };
alternatively, can catch changes made directly on dependencyproperty
with dependencypropertydescriptor
:
var descriptor = dependencypropertydescriptor.fromproperty(modelvalueproperty, typeof(yourtype)); descriptor.addvaluechanged(this, onvaluechanged); private void onvaluechanged(object sender, eventargs e) { //... }
Comments
Post a Comment