Edit default Errotemplate layout

Asked

Viewed 43 times

2

I implemented the interface Idataerrorinfo, that is working according to the image below.

Error template

I didn’t create my Errortemplate, what is being used is the . NET default.

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

I already searched the MSDN and tried to use the WPF Tree Visualizer, but I was not successful.

1 answer

0


Explain in detail how to create/change a template it’s not easy to do it here.

I leave two examples that I use:

  • Redborderonerror - Apply a red border and show a tooltip with the error message when you place the mouse 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 - Apply the red color to Foreground and show a tooltip with the error message when you place the mouse 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>
    

Attribute the Style at the Textbox in this way:

<TextBox ........
    Style="{StaticResource RedBorderOnError}"
    .....
    ....../>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.