WPF ValidationRules disables PropertyChanged
Asked Answered
C

1

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>
Cylindroid answered 11/6, 2012 at 17:27 Comment(0)
S
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>
Surefooted answered 11/6, 2012 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.