【问题标题】:WPF: Validation.ErrorTemplate not hidden when adorned control (TextBox) hiddenWPF:装饰控件(文本框)隐藏时不隐藏 Validation.ErrorTemplate
【发布时间】:2010-10-07 15:11:35
【问题描述】:

我有一个 TextBox,它会根据是否在 ComboBox 中选择一个项目来隐藏。

这部分工作正常。

但是,它也设置了 ValidatesOnDataErrors,如果 TextBox 存在错误,那么当 TextBox 被隐藏时,ErrorTemplate(在 Adorner 层中)仍然存在。

我想我明白,因为 ErrorTemplate 被设置到全局 Adorner 层,它没有意识到与它没有逻辑连接的 TextBlock 已被隐藏。

对如何使用或解决此问题有任何想法吗?我尝试在 Grid 中添加一个明确的 AdornerDecorator,它绑定到 ComboBox 值。

【问题讨论】:

  • 我也在寻找这个答案。

标签: c# wpf adorner


【解决方案1】:

您显然可以将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>

【讨论】:

    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 2014-07-19
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2013-08-10
    相关资源
    最近更新 更多