如何在WPF中显示气球工具提示 [英] How can I show a balloon Tooltip in WPF

查看:123
本文介绍了如何在WPF中显示气球工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实上,我希望文本框有2个不同的工具提示。一种是显示文本框的内容类型,另一种是用于警告输入内容是否不合适。第一个效果很容易使用

As a matter of fact, I want a Textbox to have 2 different Tooltip. One is to show the textbox's content type, while the other is used to warn if the input content is not suitable. The first effect is easily implemented using

<Textbox Tooltip="tip"/>

但是,我找到了它很难实现第二个Tooltip。由于我使用正则表达式来验证输入并警告用户他们是否提交了不合适的字符串,因此如果解决方案是用C#代码而不是XAML代码提供的,则首选。

我想要第二个工具提示(或者任何可以改变我的目标,保持控制权也可以)让点头指向文本框。希望你能理解我想要表达的内容。

为什么我不能上传图片:(这样我就可以告诉你我正在努力做什么。

如果你能帮助我,我很感激:)

However, I found it difficult to implement the second Tooltip. Since I use Regex to verify the input and warn the user if they've submitted an unsuitable string, it's preferred if the solution is provided in C# code instead of XAML code.
I want the second ToolTip (or whatever that can achrieve my goal, custumizing the control is OK too) to have a point head pointing to the Textbox. Hope you can understand what I'm trying to express.
Why can't I upload a image :( so that I can show you what I'm struggling to do.
I appreciate if you can help me :)

推荐答案

请看我对这个问题的评论。



您可以在运行时始终显示任何 ToolTip 内容,使用属性内容

https://msdn.microsoft.com /en-us/library/System.Windows.Controls.ToolTip%28v=VS.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/库/ system.windows.controls.contentcontrol.content(v = vs.110)的.aspx [ ^ ]。



您甚至不必使用 Name 属性来生成工具提示来自XAML的引用成员,因为您可以从其父元素获取此引用: https://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.tooltip%28v=vs.110%29.aspx [ ^ ]。



我建议您更改事件更改时的 ToolTip 内容UI状态,特别是其父元素的状态,但它可以是其他任何东西。我还建议在WPF默认样式中使用这样的 ToolTip 元素,其中你有不同的 ToolTip 实例用于不同的UI控件。



-SA
Please see my comment to the question.

You can always show any ToolTip content during runtime, using the property Content:
https://msdn.microsoft.com/en-us/library/System.Windows.Controls.ToolTip%28v=VS.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.content(v=vs.110).aspx[^].

You don't even have to use the property Name to generate a ToolTip reference member from your XAML, because you can get this reference from its parent element: https://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.tooltip%28v=vs.110%29.aspx[^].

I suggest you change the ToolTip content on the events changing the UI state, in particular, the state of its parent element, but it can be anything else. I would also advise to work with such ToolTip elements in the WPF default style, where you have separate ToolTip instances for different UI controls.

—SA


这篇关于如何在WPF中显示气球工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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