Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.75/5 (4 votes)
See more:
I am trying to create a control that I want to control the update of the binding using the UpdateTarget method of the BindingExpression. When in the BeginInit for the control, the binding comes back null, but in the EndInit the binding has been set but it is too late to update the binding. I get the following error: "Binding cannot be changed after it has been used." the following is the code I use to get the binding and then force the UpdateSourceTrigger to be Explicit:

var binding = BindingOperations.GetBinding(this, TextProperty);
if (binding != null)
  binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
Posted
Updated 1-Mar-12 13:31pm

1 solution

Here's a simple example using that feature.
C#
<textbox name="itemNameTextBox">
         Text="{Binding Path=ItemName, UpdateSourceTrigger=Explicit}" /></textbox>


C#
// itemNameTextBox is an instance of a TextBox
BindingExpression be = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();
 
Share this answer
 
Comments
Clifford Nelson 2-Apr-12 22:40pm    
Unfortunately what I am trying to do is not require the user to specify explicit when using the control. I want to control everything in the control. Eventually I would want to take the user request, and simulate the action he requests.

Thanks for you time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900