WPF错误模板 - 红色框的扩展器的崩溃仍然可见 [英] wpf error template - red box still visible on collapse of an expander

查看:131
本文介绍了WPF错误模板 - 红色框的扩展器的崩溃仍然可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的文本框的DataSource这是一个扩展器内,并已发现,一旦验证错误被触发,如果我垮了扩展,红框中会留在文本框本来一些验证。

I'm doing some validation on the DataSource of TextBox that's within an Expander and have found that once a validation error has been triggered, if I collapse the Expander, the red box stays where the TextBox would have been.

<Expander Header="Blah Blah Blah">
  <TextBox Name="TextBox"
           Validation.ErrorTemplate="{DynamicResource TextBoxErrorTemplate}"
           Text="{Binding Path=Blah,
                          UpdateSourceTrigger=PropertyChanged,
                          ValidatesOnDataErrors=True}" />
</Expander>

我试着通过绑定错误模板的扩展的知名度,避开这一点,但是我觉得有什么不对的结合。

I've tried to get round this by binding the visibility of the Error Template to the Expander, however I think there's something wrong with the binding.

<local:NotVisibleConverter x:Key="NotVisibleConverter" />

<ControlTemplate x:Key="TextBoxErrorTemplate">
  <DockPanel>
    <Border BorderBrush="Red" BorderThickness="2" 
            Visibility="{Binding Path=IsExpanded, 
                                 Converter={StaticResource NotVisibleConverter}, 
                                 RelativeSource={RelativeSource AncestorType=Expander}}" >
      <AdornedElementPlaceholder Name="MyAdorner" />
    </Border>
  </DockPanel>
  <ControlTemplate.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
        <Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self}, 
                                Path=(Validation.Errors)[0].ErrorContent}"/>
    </Trigger>
  </ControlTemplate.Triggers>
</ControlTemplate>

我想我已经错了我的结合,有人可以把我回到轨道上吗?或者没有人知道另一个解决ErrorTemplate仍在上扩展的崩溃可见?

I guess I've gone wrong with my binding, can someone put me back on track please? Alternatively does anyone know another solution to the ErrorTemplate still being visible on the collapse of an Expander?

推荐答案

而不是做任何有约束力的,你可以将 AdornerDecorator 您的扩展器内的元素周围。你看,验证错误模板被放置在装饰器层上这样它显示了在一切之上。这是最终你的问题是什么。尽管由于膨胀是封闭的文本框是不可见的,错误的模板仍然是装饰器层上。

Rather than doing any binding, you could place an AdornerDecorator around the elements inside of your expander. You see, the validation error template is placed on the adorner layer that way it shows up on top of everything else. That's ultimately what your problem is. Even though your text box is not visible because the expander is closed, the error template is still on the adorner layer.

我相信你可以用下面的XAML解决这个问题:

I believe you can fix this with the following xaml:

<Expander Header="Blah Blah Blah">
   <AdornerDecorator>
      <TextBox Name="TextBox"
               Validation.ErrorTemplate="{DynamicResource TextBoxErrorTemplate}"
               Text="{Binding Path=Blah,
                              UpdateSourceTrigger=PropertyChanged,
                              ValidatesOnDataErrors=True}" />
   </AdornerDecorator>
</Expander>

这为扩展中专门创建了一个装饰器层。当膨胀被关闭 AdornerDecorator 也被隐藏起来,所以应该一切就可以了。

This creates an adorner layer specifically for within the expander. When the expander is closed the AdornerDecorator also gets hidden and so should everything on it.

这篇关于WPF错误模板 - 红色框的扩展器的崩溃仍然可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆