This is a WPF/MVVM project. I am using the MS Enterprise Library Validation Application Block v5.0.
The requirement is that if the value of a combobox is "Facilities" or "Other" then the Comment field must have a value.
That said, I created a custom validator and I am performing validation in this manner:
ValidationResults results = Validation.Validate<Annotation>(this.Annotation);
There are other error possibilities and those are covered with the standard VAB attributes.
This seems to be working fine. So, now, if I have an error condition, it could be any one of the rules and I have the ValidationResults collection available to interrogate in order to determine which property has the error. However, I am having trouble with applying a style for a specific element when this occurs. At one point, I was using property level validation for a given control but that doesn't work when I need to compare multiple properties for one validation rule.
vab:Validate.BindingForProperty="Text"
The property above and this style work for a simple single property validation like a StringLenghtValidator.This doesn't work in my scenario.
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
How can I get the Comments textbox to have a certain style after the multiple property custom validator reports an error?