1

Maybe I am not using ValidationRule correctly, if so, please show me the correct way.

Currently, I have implemented a class WarningForUncheckRule inherited from ValidationRule, and bind it to a binding.

<cc:StarCheckBox>
    <cc:StarCheckBox.IsChecked>
        <Binding>
            <Binding.Path>IsFavorate</Binding.Path>
            <Binding.ValidationRules>
                <vm:WarningForUncheckRule />
            </Binding.ValidationRules>
            <Binding.Mode>TwoWay</Binding.Mode>
        </Binding>
    </cc:StarCheckBox.IsChecked>
</cc:StarCheckBox>

I implement the code and return false as result (for test purpose here):

public class WarningForUncheckRule : ValidationRule
{
    public override ValidationResult Validate(object value, 
                                              CultureInfo cultureInfo)
    {
        return new ValidationResult(false, null);
    }
}

My question is if I return false here, there is only the error UI showing with error message, but the UI status is still changed.

Is it possible to use false ValidateResult to prevent the UI from being update?

If no, is there other way in binding to accomplish this?

Kapitán Mlíko
  • 4,498
  • 3
  • 43
  • 60
winterTTr
  • 1,739
  • 1
  • 10
  • 30

1 Answers1

0

Invoke property changed on the viewmodel after the validation and it shall return the old value to UI which was before the edit.

VidasV
  • 4,335
  • 1
  • 28
  • 50