WPFvalidation(IDataErrorInfo)和选项卡聚焦问题

我有一个TextBox绑定到一个实现IDataErrorInfo的对象的属性。 我设置了TextBoxValidation.ErrorTemplate ,它工作正常。 问题是我在TabControl上有这些,如果我将标签更改为另一个标签然后返回到初始标签( TextBox所在的位置),则validation模板不再显示。 它看起来像是经过validation的(就像值是正确的),但实际上并非如此。

这是IDataErrorInfo对象 – 请注意,“正确”值是长度为2的字符串:

 public class Presenter : IDataErrorInfo { public Presenter() { this.Property = String.Empty; } public string Property { get; set; } public string Error { get { return null; } } public string this[string columnName] { get { if (columnName == "Property") { if (this.Property.Length == 2) return null; else return "Invalid property length!"; } else return null; } } } 

这是XAML:

                                   

关于我做错的任何想法?

标签项目往往会弄乱装饰(虽然我不知道为什么,我经历过它)。

我可以重现你的问题。

通过使用AdornerDecorator包装TabItem的内容来解决它。

所以:

     ....    ...  

选项卡,扩展器等不适用于validation器 – 您需要包含adornerdecorators或不使用选项卡在所有问题与WPFvalidation(IDataErrorInfo)和选项卡聚焦

我只有第一个(聚焦)标签获得样式的问题,只有一个在更改后保持不变。 这是我最终得到的解决方案(没有AdornerDecorator

  

基于这篇文章: http : //techqa.info/programming/question/1369643/wpf-error-styles-only-being-rendered-properly-on-visible-tab-of-a-tab-control