6

I have the following textbox that have a propertychanged in the viewmodel. When I insert the Binding.ValidationRules and I insert some wrong value, it doesn't trigger the propertychanged event and I don't understand why. Any help?

<TextBox Name="RiskCode" HorizontalAlignment="Left" Margin="101.923,8,0,81" TextWrapping="Wrap" Width="56.077" MaxLength="6" Validation.ErrorTemplate="{StaticResource validationTemplate}"
         Style="{StaticResource textBoxInError}">
    <TextBox.Text>
        <Binding Path="RiskCode" UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <vm:RiskCodeValidation/>
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>
akjoshi
  • 15,374
  • 13
  • 103
  • 121
Louro
  • 1,413
  • 4
  • 21
  • 27

1 Answers1

9

Use ValidationStep.

http://msdn.microsoft.com/en-us/library/system.windows.controls.validationrule.validationstep.aspx

  • RawProposedValue - Runs the ValidationRule before any conversion occurs.
  • ConvertedProposedValue - Runs the ValidationRule after the value is converted.
  • UpdatedValue - Runs the ValidationRule after the source is updated.
  • CommittedValue - Runs the ValidationRule after the value has been committed to the source.

By default, it's RawProposedValue, which prevents the binding to source from ever occurring - hence your confusion. Use a different option instead:

 <Binding.ValidationRules>
   <vm:RiskCodeValidation ValidationStep="UpdatedValue" />
 </Binding.ValidationRules>
Ross
  • 4,460
  • 2
  • 32
  • 59