How to create a similar template for this?

I saw on several sites where I published some images of my applications using the style for ErrorTemplate as follows:

enter image description here

Do you know where I can find him?

+4
source share
2 answers

This is similar to Adorner . The idea is to draw something above / next to the control where it is defined, which is also not affected by the transformations applied to the scene.

For example, you can define an Adorner in the Style your TextBox .

Something like this (pseudo code):

 <Style TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> ........ ........ <AdornerDecorator Grid.Column="0" Grid.Row="0"> ......... ......... </AdorenrDecorator> </ControlTemplate> </Setter.Value> </Setter> </Style> 

A full example (for ScrollViewer , but the same one) can be found here

+1
source

I just whipped one, worked hard, but it works in my WPF test application (using .Net 4.0). I really wanted something like this for the application I'm working on, so your question was a convenient excuse for creating it. =)

This code uses the attached Validation.ErrorTemplate property to create a ControlTemplate that sets a red border to highlight the checked control, and then a Popup that contains an error message for the control. I should have received an error message from the tested ToolTip control, because the TextBox inside the template did not seem to have access to the Validation class itself.

The tooltip message closes when the control being tested loses focus and reappears (if there is an error) when it receives focus again.

Here is a screenshot: Screen shot

Here is the gist code: https://gist.github.com/1672789

I am open to any comments or improvements that anyone has suggested.

+5
source

Source: https://habr.com/ru/post/1392762/


All Articles