pass Validation error to UI element in WPF?

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2010-03-15T21:14:24Z Indexed on 2010/03/15 23:09 UTC
Read the original article Hit count: 369

Filed under:
|
|
|
|

I am using IDataErrorInfo to validate my data in a form in WPF. I have the validation implemented in my presenter.

The actual validation is happening, but the XAML that's supposed to update the UI and set the style isn't happening.

Here it is:

  <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}"/>
                    <Setter Property="Background" Value="Red"/>
                </Trigger>
        </Style.Triggers>
    </Style>

The problem is that my binding to Validation.Errors contains no data. How do I get this data from the Presenter class and pass it to this XAML so as to update the UI elements?

EDIT:

Textbox:

 <TextBox Style="{StaticResource textBoxInError}" Name="txtAge" Height="23" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150">
            <TextBox.Text>
                <Binding Path="StrAge" Mode="TwoWay"
                         ValidatesOnDataErrors="True"
                         UpdateSourceTrigger="PropertyChanged"/>
            </TextBox.Text>

The validation occurs, but the style to be applied when data is invalid is not happening.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvp