我有一个隐藏的TextBox,具体取决于是否在ComboBox中选择了一个项目.
这部分工作正常.
但是,它也设置了ValidatesOnDataErrors,如果TextBox存在错误,那么当TextBox被隐藏时,ErrorTemplate(在Adorner层中)仍然存在.
我想我明白,因为ErrorTemplate被设置到全局Adorner层,它没有意识到它没有逻辑连接的TextBlock已被隐藏.
有关如何使用或围绕此工作的任何想法?我已经尝试在Grid中添加一个显式的AdornerDecorator,它绑定到ComboBox值.
您显然可以将其与可见性AdornerElementPlaceholder本身的可见性绑定在一起.这是我的代码:
<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>
Run Code Online (Sandbox Code Playgroud)