How can I get a button to reset text in a textbox to a known value? In my example the validation rule is triggered so I can't use the button command to update the property, which is good because I don't want the property set if it's not valid. I just want the button to basically reset the value in xaml without involving the property. How would I do that?

   <TextBox Grid.Column="1" Grid.Row="9" HorizontalAlignment="Left"  Height="20" Width="105" Name="Elevation"
             Validation.ErrorTemplate="{StaticResource validationTemplate1}" Style="{StaticResource textBoxInError}">
        <TextBox.Text >
            <Binding Path="Elevation" Mode="TwoWay" UpdateSourceTrigger="LostFocus">
                    <rules:NotEmptyValidationRule ValidatesOnTargetUpdated="True" ValidationStep="RawProposedValue"/>
                    <rules:DoubleValidationRule ValidatesOnTargetUpdated="True" ValidationStep="RawProposedValue"/>
 <Button Grid.Column="2" Grid.Row="9" Height="20" Command="{Binding ClickResetCommand}" CommandParameter="Elevation" >R</Button>

Still looking for a XAML solution but for now I've change the button to use OnClick and in the code behind using the following...

  case "Elevation":
   Elevation.Text = "50";
   Validation.ClearInvalid(Elevation.GetBindingExpression(TextBox.TextProperty) ?? throw new InvalidOperationException());

0 Answers