【问题标题】:How to change AdornerLayer to show ValidationError (WPF)如何更改 AdornerLayer 以显示 ValidationError (WPF)
【发布时间】:2018-10-16 06:14:24
【问题描述】:

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

【问题讨论】:

  • 创建一个新的 Control 或 UserControl 或覆盖包含 TextBox 和您的按钮的 TextBox 模板,并在此新控件或模板化的 TextBox 上应用装饰器。

标签: wpf wpf-controls adorner adornerlayer adornerdecorator


【解决方案1】:

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

Validation.ValidationAdornerSite="{绑定 RelativeSource={RelativeSource Mode=TemplatedParent}}"

TextBox 的附加属性。

【讨论】:

    猜你喜欢
    • 2011-08-01
    • 2012-06-20
    • 2016-10-15
    • 2016-02-24
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    相关资源
    最近更新 更多