Question

I've seen in several sites where publish some images of their applications using a style for ErrorTemplate like this:

enter image description here

Do you know where can I find it?

Was it helpful?

Solution

This looks much like Adorner. The idea is to draw something above/near the control where its defined which is not also affected by transformations applied to scene.

For example you can define a Adorner in Style of your TextBox.

Something like this (a pseudocode):

<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 complete example (for ScrollViewer, but the ides is the same) can find here

OTHER TIPS

I just whipped one up, took a little tinkering but it works in my WPF test application (using .Net 4.0). I actually wanted something like this for an application I'm working on, so your question was a convenient excuse to make one. =)

This code uses the Validation.ErrorTemplate attached property to create an ControlTemplate that sets up a red border to outline the validated control, and then a Popup that contains the error message for the control. I had to get the error message from the validated control's ToolTip property because the TextBox inside the template didn't seem to have access to the Validation class itself.

The popup error message closes when the validated control looses focus, and reappears (if there is an error) when it gains focus again.

Here's a screenshot: Screenshot

Here's the gist code: https://gist.github.com/1672789

I'm open to any comments or improvements anyone would offer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top