Validator interfers with IsDirty

Oct 19, 2016 at 2:01 PM
I have the following TextBox:
<TextBox Name="FormulaID_TextBox"
                Width="50"
                Margin="0,10,10,10">
    <TextBox.Text>
        <Binding Path="SelectedStateRule.ChildSupportRule.FormulaID" 
                        UpdateSourceTrigger="PropertyChanged">                            
        </Binding>
</TextBox.Text>
When I run my code with this TextBox everything works as expected, the IsDirty flag is properly changing based on input.

I added the following validation to this checkbox as such:
<TextBox Name="FormulaID_TextBox"
                Width="50"
                Margin="0,10,10,10">
    <TextBox.Text>
        <Binding Path="SelectedStateRule.ChildSupportRule.FormulaID" 
                        UpdateSourceTrigger="PropertyChanged">                            
            <Binding.ValidationRules>
                <vm:NumericValidator ValidatesOnTargetUpdated="True" />
            </Binding.ValidationRules>
        </Binding>
</TextBox.Text>
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            Decimal _number;
            if (!Decimal.TryParse((value as string), out _number) && !String.IsNullOrEmpty(value as string))
            {
                return new ValidationResult(false, "Value must be numeric");
            }

            return ValidationResult.ValidResult;
        }
Now, the TextBox changes the IsDirty flag ONLY when the value is valid. If the value is not valid (i.e., 'abc') the IsDirty flag does not change.

Is this intended behavior for the IsDirty flag? Is there something special I need to do to have the IsDirty flag still change even when the value is invalid?
Oct 20, 2016 at 7:11 AM
Hi Brian,

Long time .. happy to assist. Would you perhaps be able to copy your question over to the home of Simple MVVM Toolkit on GitHub?

https://github.com/tonysneed/SimpleMvvmToolkit/issues

That's where I'm tracking issues these days.

Thanks!
Tony
Oct 20, 2016 at 12:25 PM
Done. Thanks for being so responsive!



Brian

If you can't explain it simply, you don't understand it well enough. - Albert Einstein