代码之家  ›  专栏  ›  技术社区  ›  rrhartjr

wpf:validation.errorTemplate在修饰控件(文本框)隐藏时不隐藏

  •  1
  • rrhartjr  · 技术社区  · 14 年前

    我有一个根据是否在组合框中选择了某个项目而隐藏的文本框。

    这部分工作得很好。

    但是,它还设置了validatesOndataerrors,如果文本框存在错误,则当文本框被隐藏时,错误模板(在修饰层中)将保留。

    我想我理解,因为错误模板被设置到全局修饰层中,它没有意识到它没有逻辑连接的textBlock被隐藏了。

    有什么关于如何处理这个的想法吗?我尝试在一个绑定到ComboBox值的网格中添加一个显式的AdornerDecorator。

    1 回复  |  直到 14 年前
        1
  •  8
  •   Jordan    14 年前

    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>