Explicit control of how the source is updated
Posted by: Mark Shurmer
In a previous post, I described how you can get a binding to update in real time - i.e. as you type.
Sometimes however, you want to control the updating more closely, i.e. in code. For example, you may want to do the update only when a timer has ticked.
There is a little used argument for UpdateSourceTrigger (well in 18 months of using WPF I’ve never seen it used :-)) , namely Explicit that allows you to do that.
Given some xaml like:
<ComboBox Name=”cbUsers” SelectedValuePath=”Name” />
<TextBox Name=”tbUserName” Text=”{Binding ElementName=cbUsers, Path=SelectedValue}” />
When you add UpdateSourceTrigger=Explicit to the TextBox, you can control the updating by telling the binding mechanism to update.
<TextBox Name=”tbUserName” Text=”{Binding ElementName=cbUsers, Path=SelectedValue, UpdateSourceTrigger=Explicit}” />
How do you do that? That’s where the magic lies ![]()
You need to get the BindingExpression for the TextBox:
BindingExpression binding = tbUserName.GetBindingExpression(TextBox.TextProperty);
Then update the linked source( the textbox):
binding.UpdateSource();
bingo



You must be logged-in to post a comment. Log-in/Register