Experimenting with WPF validating input, I tried to use ToolTip for displaying results of TextBox input validation, like this:
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter
Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
It seemed for me very inconvenient, that ToolTip is shown not in the process of typing text in the Textbox, at the moment when validating error occurs, but only after mousepointer put intentionally over the TextBox.
This seems violating user expectation regarding usability of UI, so I prefered putting the Validation Error results in a separate TextBlock, automatically and instantly appearing at the moment, when input validation error occurs.
But maybe I'm wrong and don't use ToolTip properly? Maybe there are settings of ToolTip properties making ToolTip able appearing without intentional mousehover over TextBox?
Edited (added):
Using ToolTip for displaying results of TextBox input validation I have found in Microsoft MSDN documentation:
https://docs.microsoft.com/en-us/dotnet/desktop/wpf/data/?view=netdesktop-5.0&redirectedfrom=MSDN#data-validation
Do you use ToolTips for showing validation errors? If so, how you get along with the fact that user can never see it (if he/she doesn't guess to hover a mouse over a textbox)?
In this article, we will see how validation can be done in WPF and also how the error can be displayed. There are 3 ways in which the validation can be done in WPF. The example is very simple, we will add validation to the name property such that the characters of name is >6 and <10.
I found a way to implement ToolTip with the returned error message from the validation class that you might create to validate your input. Adding <Style> for the TextBox with Style.Trigger as followed: <Style TargetType=" {x:Type TextBox}" x:Key="ToolTipError"> <!--
The following example uses XAML to specify a ToolTip object as the tooltip of a TextBox element. Note that the example specifies the ToolTip by setting the FrameworkElement.ToolTip property. The following example uses code to generate a ToolTip object. The example creates a ToolTip ( tt) and associates it with a Button.
You can also define a tooltip as a ToolTip object. The following example uses XAML to specify a ToolTip object as the tooltip of a TextBox element. Note that the example specifies the ToolTip by setting the FrameworkElement.ToolTip property.
I believe you are using ToolTip the wrong way, the ToolTip property is meant to provide small contextual help to the user about a certain control when they hover their mouse over it, that's why it only appears on mouse-overs.
For example, if you have a text box for a user to enter their phone number, you may want to provide a tooltip saying "Please type your phone number here."
For form validation, your TextBlock idea sounds much better. Plus you have great control over the display since its a full fledge control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With