我有一个文本框,它根据是否在组合框中选择了一个项目而被隐藏。
这部分工作正常。
但是,它也设置了 ValidatesOnDataErrors 并且如果 TextBox 存在错误,那么当 TextBox 被隐藏时,ErrorTemplate(在 Adorner 层中)仍然存在。
我想我明白,因为 ErrorTemplate 被设置到全局 Adorner 层,它没有意识到它没有逻辑连接的 TextBlock 已被隐藏。
关于如何使用或解决此问题的任何想法?我尝试在 Grid 中添加一个显式的 AdornerDecorator,它绑定(bind)到 ComboBox 值。
最佳答案
您显然可以绑定(bind) 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>
关于c# - WPF:装饰控件(文本框)隐藏时不隐藏 Validation.ErrorTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3883092/