Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF:Validation.ErrorTemplate在装饰控件(文本框)隐藏时未隐藏_C#_Wpf_Adorner - Fatal编程技术网

C# WPF:Validation.ErrorTemplate在装饰控件(文本框)隐藏时未隐藏

C# WPF:Validation.ErrorTemplate在装饰控件(文本框)隐藏时未隐藏,c#,wpf,adorner,C#,Wpf,Adorner,我有一个文本框,它会根据是否在组合框中选择某个项目而隐藏 这部分很好用 但是,它还设置了ValidatesOnDaerErrors,如果TextBox存在错误,则当TextBox隐藏时,装饰器层中的ErrorTemplate将保留 我想我理解,因为ErrorTemplate被设置到全局装饰器层中,所以它没有意识到它没有逻辑连接的TextBlock被隐藏了 关于如何处理或解决这个问题有什么想法吗?我尝试在网格中添加一个显式的AdornerDecorator,它绑定到ComboBox值。显然可以将A

我有一个文本框,它会根据是否在组合框中选择某个项目而隐藏

这部分很好用

但是,它还设置了ValidatesOnDaerErrors,如果TextBox存在错误,则当TextBox隐藏时,装饰器层中的ErrorTemplate将保留

我想我理解,因为ErrorTemplate被设置到全局装饰器层中,所以它没有意识到它没有逻辑连接的TextBlock被隐藏了


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

显然可以将AdorneRementPlaceHolder的可见性绑定到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>

显然,您可以将AdorneRementPlaceHolder的可见性绑定到装饰器本身的可见性。这是我的密码:

<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>

我也在寻找这个答案。我也在寻找这个答案。