Several validation rules and validation patterns in WPF

Does anyone have a tactic to solve several validation rules and patterns for these validation rules.

Example:

I want to have two validation rules (data required)

I want either ...

One template that can change is displayed depending on which rule is fired or Two templates that are displayed depending on which rule is running

+3
source share
2 answers

Ok, so I figured out an approach that works, and I was hoping to get feedback from anyone who might have an interest in this.

ValidationRule:

, "ErrorObject" IsRequired

    public class ErrorObject
    {
        public bool IsRequired { get; set; }
        public string Message { get; set; }
    }

....

return new ValidationResult(false, new ErrorObject() { IsRequired = true, Message = "Is Required" });

:

. ( * )

            <Border
                BorderBrush="Red"
                CornerRadius="3"
                BorderThickness="1">
                <AdornedElementPlaceholder
                    x:Name="errorAdorner" />
            </Border>
            <TextBlock
                Text="*"
                Foreground="Red"
                Visibility="{Binding ElementName=errorAdorner, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent.IsRequired, Converter={StaticResource BooleanToVisibilityConverter}}" />

, , , . MS , !!!

+2

, , 100% , , , .

? WPF

.

0

Source: https://habr.com/ru/post/1750204/


All Articles