How to change AdornerLayer to show ValidationError (WPF)

348 Views Asked by At

I created a descendant of RangeBase. In this descendant I created Template where I used TextBox control. Now I need validate Value (of inherited RangeBase) when is invalid value is entered to TextBox(contained in Template).
And here is my problem: If I want to validate new descendant control, only TextBox is adorned with validation error(using appropriate ControlTemplate) - TextBox contains appropriate validation in binding of Text property(  )
But I need it to be adorned my new control, as a whole(not just TextBox):enter image description here.
Is there a way to do this?
Perhaps it's needed to change the AdornerLayer so that the adorner does not appear on the TextBox, but on my new element.

1

There are 1 best solutions below

0
On

You need to move adorner site from validated control to the main control(a descendant of RangeBase). To this, you can simply use the:

Validation.ValidationAdornerSite="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}}"

attached property to the TextBox.