Why the data binding in this validation example works in WPF?

Posted by MartyIX on Stack Overflow See other posts from Stack Overflow or by MartyIX
Published on 2010-03-29T17:27:58Z Indexed on 2010/03/29 17:33 UTC
Read the original article Hit count: 153

Filed under:
|
|

I'm wondering how exactly the XAML sample (MSDN sample) works:

<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
  <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>

Questions:

  • (Validation.Errors)[0].ErrorContent - Is this code somehow checked by WPF? Because Validation.Errors may be an empty collection and in ordinary C# code this code may throw an exception. If this data-binding returns null for valid input - the null value is then casted to empty string (in a text control for example)?
  • The index 0 corresponds to the first error message. How can I return more error messages from Validate method?

Thank you for responses!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding