How to use IDataErrorInfo.Error in a WPF program?

You should modify the TextBox style so it shows what’s wrong with the property. Here is a simple example that shows the error as tooltip:

<Style TargetType="TextBox">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
                        Path=(Validation.Errors).CurrentItem.ErrorContent}" />
            </Trigger>
        </Style.Triggers>
</Style>

Just put it inside Application.Resources from your app.xaml file and it will be aplied for every textbox of your application:

<Application.Resources>
    <Style TargetType="TextBox">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
                            Path=(Validation.Errors).CurrentItem.ErrorContent}" />
                </Trigger>
            </Style.Triggers>
    </Style>
</Application.Resources>

Leave a Comment