Search code examples
wpfbindingtextboxborderextern

How to remove extra border in WPF TextBox?


I have a problem with WPF TextBox. I have an ItemsControl with TextBox controls, which binds to double properties in some ViewModel. For these TextBox controls I have a DataTrigger

<DataTrigger Binding="{c:Binding 'IsCorrect'}" Value="False">
      <Setter Property="BorderThickness" Value="5"/>
      <Setter Property="BorderBrush" Value="GreenYellow"/>
      <Setter Property="Background" Value="#FFD2D2"/>
</DataTrigger>

It changes BorderThickness, BorderBrush and Background of the TextBox if there was entered a wrong number. But, if I remove all text from TextBox, it will not set data to binding property and change BorderThickness and BorderBrush properties, and if DataTrigger styles have been already set, there will be second border, which is extern for DataTrigger's made border.

Result Image:

Screenshot of the result

On the image GreenYellow border is set by DataTrigger and Red extern border set by itself.

So the QUESTION is - what is this extern border? and how to remove it?!


Solution

  • So the QUESTION is - what is this extern border?

    It's part of the default Validation.Error template.

    and how to remove it?!

    Define a custom empty Validation.Error template:

    <TextBox>
        <Validation.ErrorTemplate>
            <ControlTemplate />
        </Validation.ErrorTemplate>
    </TextBox>
    

    Or in a Style:

    <Style TargetType="TextBox">
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate />
            </Setter.Value>
        </Setter>
    </Style>