Click here to Skip to main content
12,950,268 members (66,828 online)
Rate this:
Please Sign up or sign in to vote.
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 1-Mar-12 13:12pm
Updated 1-Mar-12 13:31pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

// itemNameTextBox is an instance of a TextBox
BindingExpression be = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 2 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100