Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WPFBinding
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:12
Edited 1 Mar '12 - 13:31


1 solution

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);
be.UpdateSource();
  Permalink  
Comments
Clifford Nelson - 2 Apr '12 - 22:40
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,356
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 2 Apr 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid