Reputation: 4443
I have text box and i want to validate is valid email in textbox on button "save" click.
But standard validation have strange behaviour. When i print new email it always with error and this is wery annoing. I want to show error only after button click and then text box must become valid if got focus. Is there are standard way to do this in THE MODEL-VIEW-VIEWMODEL.
Upvotes: 2
Views: 883
Reputation: 24713
The default behavior for changing the bound value in a TextBox
is via LostFocus
. You would need to change the UpdateSourceTrigger
to be explicit.
<TextBox Name="MyTextBox"
Text="{Binding Path=FirstName, UpdateSourceTrigger=Explicit}" />
Then in your code behind you now have to explicitly call UpdateSource
via your Button
click handler.
BindingExpression be = MyTextBox.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();
Upvotes: 3