I have a TextBox that gets hidden depending on whether an item is selected in a ComboBox.
This part works fine.
However, it also has ValidatesOnDataErrors set and if the TextBox has an error present, then when the TextBox gets hidden, the ErrorTemplate (in the Adorner layer) remains.
I think I understand that because the ErrorTemplate gets set into the global Adorner layer, it doesn't realize that the TextBlock, which it has no logical connection to, has been hidden.
Any thoughts on how to work with or around this? I've tried adding an explicit AdornerDecorator inside a Grid, which is bound to the ComboBox value.
You apparently can bind the visibility of the AdornerElementPlaceholder
to that of the adorner itself. Here is my code:
<ControlTemplate x:Key="EmptyErrorTemplate">
<Border Background="Transparent" BorderBrush="Transparent" BorderThickness="0" IsHitTestVisible="false"
Visibility="{Binding ElementName=placeholder, Path=AdornedElement.Visibility}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,-30,0" Text="!"
Foreground="Red"
FontSize="34"
VerticalAlignment="Center"/>
<AdornedElementPlaceholder Name="placeholder" />
</StackPanel>
</Border>
</ControlTemplate>