如何更改AdornerLayer以显示ValidationError(WPF)

问题描述 投票:-1回答:1

我创建了RangeBase的后代。在这个后代我创建了模板,我使用TextBox控件。现在我需要验证Value(继承的RangeBase),当无效值输入到TextBox(包含在Template中)时。 这是我的问题:如果我想验证新的后代控件,只有TextBox装饰有验证错误(使用适当的ControlTemplate) - TextBox包含适当的验证绑定Text属性() 但我需要它装饰我的新控件,作为一个整体(不仅仅是TextBox):enter image description here。 有没有办法做到这一点? 也许需要更改AdornerLayer,以便装饰器不会出现在TextBox上,而是放在我的新元素上。

wpf wpf-controls adorner adornerlayer adornerdecorator
1个回答
0
投票

您需要将adorner站点从经过验证的控件移动到主控件(RangeBase的后代)。对此,您可以简单地使用:

Validation.ValidationAdornerSite =“{Binding RelativeSource = {RelativeSource Mode = TemplatedParent}}”

附加属性到TextBox。

© www.soinside.com 2019 - 2024. All rights reserved.