Validation ErrorTemplate not showing on data errors

后端 未结 1 2036
庸人自扰
庸人自扰 2020-12-25 13:42

This is a bit of a WPF whodunnit! My validation temples it not appearing when expected

The Problem

Basically, I am using IDataErrorIn

相关标签:
1条回答
  • 2020-12-25 14:03

    Cracked it.

    The ErrorTemplate attached property uses the adorner layer to show error templates on data validation failures reported via IDataErrorInfo. The Adorner layer is not always available for all controls in all situations. Your control or one of its parents needs to explicitly provide one.

    The default Window control template contains an AdornerDecorator which enables the adorner layer for its children. This why my other window showed my error templates just fine, because this window used the default control template

    The window which didn't show my error template had used a style which provided a ControlTemplate for my window. This control template did not provide an <AdornerDecorator>, hence no adorner layer to show my error template.

    The fix was as simple as wrapping my window control template with <AdornerDecorator>.

    0 讨论(0)
提交回复
热议问题