Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I validate multiple object properties and then apply a style with a tooltip on one of my form elements?
    text
    copied!<p>This is a WPF/MVVM project. I am using the MS Enterprise Library Validation Application Block v5.0. </p> <p>The requirement is that if the value of a combobox is "Facilities" or "Other" then the Comment field must have a value.</p> <p>That said, I created a custom validator and I am performing validation in this manner:</p> <pre><code>ValidationResults results = Validation.Validate&lt;Annotation&gt;(this.Annotation); </code></pre> <p>There are other error possibilities and those are covered with the standard VAB attributes.</p> <p>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.</p> <pre><code>vab:Validate.BindingForProperty="Text" </code></pre> <p>The property above and this style work for a simple single property validation like a StringLenghtValidator.This doesn't work in my scenario. </p> <pre><code>&lt;Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="Background" Value="White"/&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Validation.HasError" Value="true"&gt; &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>How can I get the Comments textbox to have a certain style after the multiple property custom validator reports an error?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload