Click here to Skip to main content
15,886,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
HTML
<Textbox Tooltip="tip"/>
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 :)
Posted
Updated 10-Sep-15 5:28am
v3
Comments
Sergey Alexandrovich Kryukov 10-Sep-15 12:20pm    
Not clear what's the problem. Of course you can always use C# code directly. But what do you want to show, two tooltips at the same time? And what's the problem? Secondly, two tooltips at the same time could be confusing to the user, so why not showing only one with different content, depending on current UI state and data?
—SA

1 solution

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
 
Share this answer
 
Comments
Wu Jiecheng 10-Sep-15 20:45pm    
What I'm trying to do is to show 2 different tooltips at 2 different time. The first tooltip is shown when the mouse is hovering over the textbox (default tooltip can do that), while the second one is shown to warn the user when he clicks the "submit" button and text of the textbox is not suitable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900