WPF TextBox Validating results ToolTip

◇◆丶佛笑我妖孽 提交于 2019-12-05 00:20:43

问题


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:

http://msdn.microsoft.com/en-us/library/ms752347.aspx#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)?


回答1:


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.



来源:https://stackoverflow.com/questions/2119494/wpf-textbox-validating-results-tooltip

工具导航Map