Note that there are some explanatory texts on larger screens.

plurals
  1. POwpf error template - red box still visible on collapse of an expander
    text
    copied!<p>I'm doing some validation on the DataSource of TextBox that's within an Expander and have found that once a validation error has been triggered, if I collapse the Expander, the red box stays where the TextBox would have been.</p> <pre><code>&lt;Expander Header="Blah Blah Blah"&gt; &lt;TextBox Name="TextBox" Validation.ErrorTemplate="{DynamicResource TextBoxErrorTemplate}" Text="{Binding Path=Blah, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /&gt; &lt;/Expander&gt; </code></pre> <p>I've tried to get round this by binding the visibility of the Error Template to the Expander, however I think there's something wrong with the binding.</p> <pre><code>&lt;local:NotVisibleConverter x:Key="NotVisibleConverter" /&gt; &lt;ControlTemplate x:Key="TextBoxErrorTemplate"&gt; &lt;DockPanel&gt; &lt;Border BorderBrush="Red" BorderThickness="2" Visibility="{Binding Path=IsExpanded, Converter={StaticResource NotVisibleConverter}, RelativeSource={RelativeSource AncestorType=Expander}}" &gt; &lt;AdornedElementPlaceholder Name="MyAdorner" /&gt; &lt;/Border&gt; &lt;/DockPanel&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="Validation.HasError" Value="true"&gt; &lt;Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; </code></pre> <p>I guess I've gone wrong with my binding, can someone put me back on track please? Alternatively does anyone know another solution to the ErrorTemplate still being visible on the collapse of an Expander?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload