Wpf textbox error validating

field A should only be validated if field B is true) using nothing but attributes (and of course a little bit of helper code, which I’ll give you). This is where Validation Attribute and the framework-provided implementations exist.

wpf textbox error validating-52

And now it is also possible to set the values by a Trigger, like the Background as I wanted.

It is also possible to set the values in XAML parts that are using the Style.

Recently I wanted to change the Background of a Text Box, if some own Validation Rule failed. I tried several things and I gained more insights into styling and especially into styling wrong validated elements. If you are not familiar with WPF validation, here you can find excellent descriptions of how to use validation in WPF: I tried several combinations with Validation.

This is the working code that changes the Background of a Text Box in case of error.

On Property Changed("Is Last Name Required"); } } [Required If("Is Last Name Required", true, Error Message = "Last name is required.")] public string Last Name { get { return Name; } set { Name = value; this.