Edit default ErroTemplate layout

2

I've implemented the IDataErrorInfo interface, which is working as shown below.

I have not created my ErrorTemplate , which is being used is the .NET standard.

I would like to know if there is somewhere the XAML code of this error template, because my intention is to create my own error template based on it.

I have already searched the MSDN and tried to use the WPF Tree Visualizer, but I did not succeed.

    
asked by anonymous 28.05.2015 / 16:01

1 answer

0

Explaining in detail how to create / change a template is not easy to do here.

I leave two examples that I use:

  • RedBorderOnError - Applies a red border and shows a tooltip with the error message when hovering over it.

    <Style x:Key="RedBorderOnError" TargetType="{x:Type 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>
    
  • RedTextOnError - Applies the red color to Foreground and shows a tooltip with the error message when you hover over it.

    <Style x:Key="RedTextOnError" TargetType="{x:Type TextBox}">
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <DockPanel LastChildFill="True">
                        <Border BorderBrush="Transparent" BorderThickness="1">
                            <AdornedElementPlaceholder />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self}, 
                       Path=(Validation.Errors).CurrentItem.ErrorContent}"/>
                <Setter Property="Foreground" Value="Red"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    

Assign the Style to the TextBox like this:

<TextBox ........
    Style="{StaticResource RedBorderOnError}"
    .....
    ....../>
    
28.05.2015 / 16:52