WPF TextBox 验证结果工具提示 [英] WPF TextBox Validating results ToolTip

查看:68
本文介绍了WPF TextBox 验证结果工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用WPF验证输入,我尝试使用ToolTip来显示TextBox输入验证的结果,如下所示:

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.

这似乎违反了用户对 UI 可用性的期望,所以我更喜欢将验证错误结果放在一个单独的 TextBlock 中,当输入验证错误发生时,此时会自动并立即出现.

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?

编辑(添加):

使用工具提示显示我在 Microsoft MSDN 文档中找到的文本框输入验证的结果:

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

您是否使用工具提示来显示验证错误?如果是这样,您如何处理用户永远看不到它的事实(如果他/她不猜测将鼠标悬停在文本框上)?

推荐答案

我相信您使用 ToolTip 的方式是错误的,ToolTip 属性旨在为用户将鼠标悬停在某个控件上时提供小的上下文帮助它,这就是为什么它只出现在鼠标悬停.

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."

对于表单验证,您的 TextBlock 想法听起来要好得多.此外,您可以很好地控制显示,因为它是完全成熟的控制.

For form validation, your TextBlock idea sounds much better. Plus you have great control over the display since its a full fledge control.

这篇关于WPF TextBox 验证结果工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆