Workaround For When Textbox Border Remains After Expander is Closed When Using ValidatesOnDataErrors or DataErrorValidationRule

February 3 2009

Recently hit a WPF issue with IDataErrorInfo where using ValidatesOnDataErrors with a TextBox creates a border around the textbox that doesn’t go away when used with an Expander. Screen shot below before closing expander: 

Screenshot after closing expander:


 

The workaround?  Create a style for Textbox (or TextboxBase, depending) which blows away the validation error template like this:

<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>

And then manually sets the border, like this:

<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
<Setter TargetName="Border" Property="Background" Value="Red"/>
</Trigger>

That did the trick. Download a complete sample of the fix. 

Comments (3) -

2/1/2009 1:24:00 PM #

treading man
          

henry

2/1/2009 6:25:00 PM #

tread man
          

henry cheund

2/10/2009 12:14:00 AM #

The other thing you could have done is just wrap the content of the expander in an AdornerDecorator.  The border is drawn in the adorner layer, and by default a window only has one adorner layer.  Adding the AdornerDecorator will add a new adorner layer which will have its visibility controlled by the expander.
          

Caleb Vear

Add comment

Enter your name, handle, alias, or email.

We'll incarnate your avatar from the services below.



biuquote
Loading