Just a short question :
In wpf, how do I set and get updatesourcetrigger of a textbox in codebehind ?
Thanks
Update :
I follow AngleWPF's code :
var bndExp = BindingOperations.GetBindingExpression(this, TextBox.TextProperty);
var myBinding
= bndExp.ParentBinding;
var updateSourceTrigger = myBinding.UpdateSourceTrigger;
But I got the exception :
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll Additional information: Exception has been thrown by the target of an invocation.
What do you mean by
UpdateSourceTriggerofTextBox? You mean to sayUpdateSourceTriggerofTextBox.TextProperty'sBinding?E.g. if you have a
TextBoxnamedmyTextBoxhaving itsTextproperty bound to some source then you can easily get it'sUpdateSourceTriggerandBindingobject viaGetBindingExpression()call.But it is tricky to set
UpdateSourceTriggerfor an already used binding. E.g. in the above case you wont be able to set themyBinding.UpdateSourceTriggerto something else. This is not allowed when a binding object is already in use.You may have to deep clone the binding object and set new
UpdateSourceTriggerto it and assign it back to theTextBox. Cloning does not exist forBindingclass. You may have to write your own cloning code for the same.Alternately ou can also try to detatch the existing Binding and update it and assign it back...
Let me know if any of these tips helps.