WPF Expander still showing advertiser with compression validation error

I have a style for TextBox

to show a validation error message like this:

<Style 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}"/>
           </Trigger>
       </Style.Triggers>
       <Setter Property="Validation.ErrorTemplate">
           <Setter.Value>
               <ControlTemplate>
                   <StackPanel Orientation="Horizontal">
                       <Border BorderBrush="{Binding Path=ErrorContent, 
                               Converter={StaticResource ValidationErrorToBrushConverter}}" BorderThickness="2">
                           <AdornedElementPlaceholder />
                       </Border>
                       <Image Name="image1" Height="14" Width="14" Stretch="Fill" Margin="1,1,1,1" 
                              Source="{Binding Path=ErrorContent, 
                              Converter={StaticResource ValidationErrorToImageSourceConverter}}" 
                              ToolTip="{Binding Path=ErrorContent}"/>
                   </StackPanel>
               </ControlTemplate>
           </Setter.Value>
       </Setter>
   </Style>

      

TextBox

lives in Expander

. When I open Expander, it TextBox

accepts input, but does not validate if the input NullorEmpty

, or contains special characters.

My problem is that when I run the validation error, it TextBox

lights up in red and shows a message icon as a tooltip. Everything is fine so far. BUT, when I close Expander

without passing the validation, the red outline and tooltip icon are still there! Even with Expander

decreased! Just floating there ... This is not good behavior.

Any ideas on how to get the Validation stuff to hide alongside all the other controls in Expander

? Also, the style for validation is declared in the UserControl resources, not in the Expander

.

+2


source to share


3 answers


I ended up just clearing the TextBox after the Expander was closed. This way, the verification error will disappear and the drawer will be cleared and ready for another entry when the expander is opened.



0


source


I had the same problem. I fixed this by putting the AdornerDecorator as the first child of the expander. The AdornerDecorator collapses when the expander collapses, so everyone else should be gone.



0


source


I solved this same problem by setting the property Validation.ErrorTemplate

to null when the TextBox is hidden

<Style TargetType="TextBox">
    <Style.Triggers>
        <Trigger Property="IsHitTestVisible" Value="False">
            <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
        </Trigger>
    </Style.Triggers>
</Style>

      

0


source







All Articles