I'm creating a WPF window with multiple textboxes, when the user presses the OK button I want all the text boxes to be evaluated for being non-blank.
I understand that I have to use TextBoxes with 'UpdateSourceTrigger of 'Explicit', but do I need to call 'UpdateSource()' for each of them ?
e.g.
<TextBox Height="23"
HorizontalAlignment="Left"
Margin="206,108,0,0"
Text="{Binding Path=Definition, UpdateSourceTrigger=Explicit}"
Name="tbDefinitionFolder"
VerticalAlignment="Top"
Width="120" />
<TextBox Height="23"
HorizontalAlignment="Left"
Margin="206,108,0,0"
Text="{Binding Path=Release, UpdateSourceTrigger=Explicit}"
Name="tbReleaseFolder"
VerticalAlignment="Top"
Width="120" />
…
BindingExpression be = tbDefinitionFolder.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();
BindingExpression be2 = tbReleaseFolder.GetBindingExpression(TextBox.TextProperty);
be2.UpdateSource();
Best Answer
If you use
Explicit
you need to callUpdateSource
.I am not sure if this is the best approach to what you try to do though, i for one virtually never use
Explicit
, i rather bind to a copy of an object if i do not want changes to apply right away, or i store a copy and revert everything back if edits are to be cancelled.