By default, the Validation.ErrorTemplate in WPF is just a small red border without any ToolTip.
In Silverlight 4, the validation error is nicely styled out-of-the-box.
Here is a comparison of a validation error occuring in Silverlight 4 and WPF
Silverlight 4

WPF

Notice the really flat, boring look of the WPF version compared to the, in my opinion, great look in Silverlight.
Does any similar validation styles/templates exist in the WPF Framework or has anybody created nicely styled validation templates like the Silverlight version above? Or will I have to create them from scratch?
If anybody wants to try it out, the validation error above can be reproduced with the following code, works for both Silverlight and WPF
MainWindow/MainPage.xaml
<StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Top">
<TextBox Text="{Binding Path=TextProperty, Mode=TwoWay, ValidatesOnExceptions=True}"/>
<Button Content="Tab To Me..." Margin="20,0,0,0"/>
</StackPanel>
MainWindow/MainPage.xaml.cs
public MainWindow/MainPage()
{
InitializeComponent();
this.DataContext = this;
}
private string _textProperty;
public string TextProperty
{
get { return _textProperty; }
set
{
if (value.Length > 5)
{
throw new Exception("Too many characters");
}
_textProperty = value;
}
}
I studied the Silverlight version of the Validation Error Template and created a WPF version of it which looks like this
Added an animated GIF at the bottom of the post but after I finished it I noticed that it might be annoying because of the moving mouse in it. Let me know if I should remove it.. 🙂
I used a
MultiBindingwith aBooleanOrConverterto show the “tooltip-error” when theTextBoxhas Keyboard focus or the Mouse is over the upper right corner. For the fade-in animation I used aDoubleAnimationfor theOpacityand aThicknessAnimationwith aBackEase/EaseOutEasingFunctionfor theMarginUseable like this
errorTemplateSilverlightStyle
BooleanOrConverter