wpf error template - red box still visible on collapse of an expander

依然范特西╮ 提交于 2019-11-28 07:01:09
dustyburwell

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.

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>

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.

In general, debugging bindings can be done by:

  1. Sticking breakpoints in a converter (if you're using one, which you are)
  2. Checking the Output pane in Visual Studio for any debug warnings about invalid bindings

In the code you've posted, I believe it's going to be because the Value property on Setter is not a dependency property and therefore cannot be bound to.

I'll have a think about this and see if I can come up with something more helpful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!