Home » WPF

Opening a ToolTip programmatically

Hi all,

how can I open a ToolTip attached to a Control programmatically?


11 Answers Found


Answer 1


try this.



<Button Content="Button" Height="23" HorizontalAlignment="Left"Name="button1">


                <ToolTip Content="this is a button"></ToolTip>






((ToolTip) button1.ToolTip).IsOpen = true;


Best of luck

Md. Masudur Rahman

Answer 2

Hello Masadur,

I tried my very best, but your proposal does not open the ToolTip. I think that we must look in the direction of raising a RoutedEvent against the ToolTip. But I have no idea what this could be.


Answer 3


In which event you are trying to display the tooltip? I have tested it and work fine.  




Answer 4

Hi Masudur,

very nice pages on Tooltips. My compliments to this great job. I did these studies myself and know how difficult that matter is.

In my case here, I'm looking for a solution to open a ToolTip that has been already created and assigned either in XAML or C# by programming and not by hovering the mouse over the attachee (e.g. the TextBox or the Button). I have understood your message above that you proposed to open the ToolTip by sending true to the IsOpen property of the ToolTip. This does not work here, I'm afraid, and I have not found an example for this in the samples in your site.

The Event approach I mentioned has the following design idea:

Any of the MouseOver and other hover events is captured by the base Control and either converted to an event signaling the ToolTip to open itself or the ToolTip is created and shown by the base Control. So basically we would simulate a MouseOver.


Answer 6

Hi Brian,

I have some experience with adorner. This would be a possible alternate solution.

The requirement I have to implement is a little more "ToolTip"-based because the programmed Open of the ToolTip should occur with different texts in the ToolTip as an explanation of the content of the TextBox immediately when the Text is entered and the user tabs away from the TextBox. After then the ToolTip should close after its defined time and appear again on request be hovering with the mouse over the TextBox later on.

Everything works well with the ToolTip except the programmed Open. There seems to be no method or property that triggers an open. I tried IsOpen and some other.

So my idea is to raise the event against the TextBox that leads to opening of the ToolTip. I have nothing found on this in MSDN yet. The most promising candidate seems to be the ToolTipOpening event.

I'm sure that the WPF experts will have better ideas.


Answer 7

Luckily for you I am a WPF expert.  If I understand you correctly you want the tooltip to stay visible as you type.  Is this correct?  If so, what you need is the StaysOpen property.

<Grid><Grid.RowDefinitions><RowDefinitionHeight="Auto"/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><TextBoxx:Name="_textBox"><TextBox.ToolTip><ToolTip><TextBlockText="This is a tooltip"/></ToolTip></TextBox.ToolTip></TextBox><StackPanelGrid.Row="1"Orientation="Horizontal"><ButtonClick="OpenButton_Click">Show Tooltip</Button><ButtonClick="CloseButton_Click">Close Tooltip</Button></StackPanel></Grid>


privatevoid OpenButton_Click(object sender, RoutedEventArgs e)
      ((ToolTip)_textBox.ToolTip).StaysOpen = true;
      ((ToolTip)_textBox.ToolTip).IsOpen = true;

    privatevoid CloseButton_Click(object sender, RoutedEventArgs e)
      ((ToolTip)_textBox.ToolTip).StaysOpen = false;
      ((ToolTip)_textBox.ToolTip).IsOpen = false;

This basic example works perfectly.  I click the Show button and start typing, the tooltip stays visible.  It will only dissapear when I click the close button.


Answer 8

Hi Brian,

good to hear that you can help with best WPF expertise. So your example was very helpful.

Your solution does not fully covered my requirements described in my posting above (... After then the ToolTip should close after its defined time and appear again on request be hovering with the mouse over the TextBox later on .), but it showed how to open a ToolTip by my own code. Very helpfull, indeed.

I had to adjust things a little:

Because the default Placement is "Mouse" the ToolTip appeared at the button clicked, not attached to the TextBox where it belongs to. Clearing StaysOpen in the IsOpen = false clause lead to a "NotSupported" exception when hovering over the TextBox after closing the ToolTip manually.

To cure the placement problem, I added a Placement Property in XAML. After this the isOpen clause no more worked. The reason turned out to be the need for setting PlacementTarget Property when other placements than Mouse are specified. BTW: This was the reason for my original question: I was using a Placement Property of Bottom from the beginning and so IsOpen did not work.

So my final setup in C# (XAML as show by Brian) is as follows:

private void OpenButton_Click( object sender, RoutedEventArgs e ) {
  ((ToolTip)_textBox.ToolTip).Placement = PlacementMode.Bottom;
  ((ToolTip)_textBox.ToolTip).PlacementTarget = _textBox;
  ((ToolTip)_textBox.ToolTip).IsOpen = true;

private void CloseButton_Click( object sender, RoutedEventArgs e ) {
  ((ToolTip)_textBox.ToolTip).IsOpen = false;

Setting the Placement should be better done in XAML because there it is set when instantiating the ToolTip.

So everything is up to my needs except one important topic: The Tooltip should close automatically after the ShowDuration time (see above). I tried setting this with ToolTipService in XAML and in C# as an attached property: No success.

So this is my new problem : How can I activate the TollTip closing after the ShowDuration time when it has been opened by the IsOpen pattern?

Regards Uwe

Answer 9

Using the exmaple I provided; I get the desired effect by setting the TooltipService.ShowDuration property.  I am sure you will find that the tooltip will not always behave as you expect it to when trying to manipulate it's behavior programattically.  You may need the help of a timer and hide the tooltip manually.  As I mentioned earlier, I believe an adorner would be a better solution to your problem.  Good luck.


Answer 10

Hello Brian,

I tried my very best to reproduce what you wrote, but the ToolTip opened by IsOpen refused to disappear after the ShowDurationTime. Could you please have a look at the code below to guide me where the difference is?


<Windowx:Class="PamToolTip.ToolTipWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"Title="MainWindow"Height="350"Width="525"><Grid><Grid.RowDefinitions><RowDefinitionHeight="Auto"/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><TextBoxx:Name="_textBox"Margin="20"ToolTipService.ShowDuration="1000"ToolTipService.Placement="Bottom"><TextBox.ToolTip><ToolTip><TextBlockText="This is a tooltip"/></ToolTip></TextBox.ToolTip></TextBox><StackPanelGrid.Row="1"Orientation="Horizontal"Margin="20"HorizontalAlignment="Stretch"><ButtonHeight="40"Margin="0 0 10 0"Click="OpenButton_Click">Show Tooltip</Button><ButtonHeight="40"Margin="0 0 10 0"Click="CloseButton_Click">Close Tooltip</Button></StackPanel></Grid></Window>
Code behind
namespace PamToolTip {
  publicpartialclass ToolTipWindow : Window {

   public ToolTipWindow() {

   privatevoid OpenButton_Click( object sender, RoutedEventArgs e ) {
     TextBox textBox = this._textBox;
     ToolTip toolTip = (ToolTip)textBox.ToolTip;
     ((ToolTip)textBox.ToolTip).PlacementTarget = textBox;
     ((ToolTip)textBox.ToolTip).IsOpen = true;

   privatevoid CloseButton_Click( object sender, RoutedEventArgs e ) {
     ((ToolTip)_textBox.ToolTip).IsOpen = false;

Could it be that I have a bug in my .Net 4?


Answer 11

I don't think you have a bug in your .NET.  The tooltip just isn't meant to be used the way you are using it.  You may eventually get it close, but I still think an adorner is a better solution.  Good luck.



Can anyone share any ideas on how to set the background color of the tooltip when using the TooltipService object? My code looks like this:

ToolTipService.SetToolTip(pin, desc);
pushpinLayer.AddChild(pin, d);

Where pin is a pushpin object, pushpinLayer is a mapLayer object and desc is the content of the tooltip.

This works fine except I can't figure out how to set the background color of the content in the tooltip. I am very new to Silverlight.


it works fine in all cases unless I have a Windows Search window open.
what i did is as follows:
1?add ON_NOTIFY_EX(TTN_NEEDTEXT, 0, SetTipText)  
2?add EnableToolTips(TRUE),int CDialog::OnInitDialog

3?add   BOOL CWndYour::SetTipText(UINT id, NMHDR *pTTTStruct, LRESULT *pResult)  
 UINT nID = pTTTStruct->idFrom; 
 if (pTTT->uFlags & TTF_IDISHWND)  
  //?HWND ??ID值,????????HWND值???
  nID = ::GetDlgCtrlID((HWND)nID);
  if (NULL == nID)
   return FALSE;

   strcpy(pTTT->lpszText, your_string1);    

  return TRUE;
 return FALSE;  

4?set the notify for the control
thank you very much!


Hi everyone,

I want to display tooltip for items of combo-box when list is droped-down(ie open),I tried but im able pop tooltip only when list is closed (ie selection is done)

and also I tried to capture the mouse location so that i can hard code it with combo-items but wen list is dropped all windows are disabled and even mouse location is not accessible

If you   any method to trace mouse pointer location when list is dropped please post..


patil bayyapur


I am facing a starnge issue here, in my application when the Windowstate is maximized then the tooltips and the menus are appearing on the top left corner of the screen. If I restore the window to the Normal state then everything works fine
my problem is something like -

Any clues on this.




I have implemented pie chart. Issue is legend tooltip is getting overlapped with other tooltip if all values are very less.

Please tell me, what is the setting i need to modify to get rid of tooltip overlap even though all values are very less.




We have developed a VSTO Excel Add-In (.NET 3.5, Excel 2007).  On the Add-In start up method a macro is run that registered the managed code functionality as an object in a VBA module within an .xla file - exactly as is described here http://blogs.msdn.com/b/pstubbs/archive/2004/12/31/344964.aspx

We are currently trying to automate a process that opens, saves and closes all Excel files within a directory.  The hope was that when the file was opened we could run a method on the VSTO add-in making modifications to the spreadsheet before saving and closing it. (I'm using the technique described here http://blogs.msdn.com/b/andreww/archive/2007/01/15/vsto-add-ins-comaddins-and-requestcomaddinautomationservice.aspx to access the VSTO add-in from the automating program.)  

However, when excel is opened programmatically, and I run a method on the Add-In which calls a macro I get the error message:

Cannot run the macro 'RegisterCallback'. The macro may not be available in this workbook or all macros may be disabled.

The code I am using to run the macro is 


    Application.Run("RegisterCallback", Functions, missing,
     missing, missing, missing, missing, missing, missing, missing, missing,
     missing, missing, missing, missing, missing, missing, missing, missing,
     missing, missing, missing, missing, missing, missing, missing, missing,
     missing, missing, missing, missing);


 and I have also tried prefixing the macro name with the full path of the .xla file in which it lies.

According the installed property of the add-in corresponding to this .xla file is true, and macros are enabled (the .xla file is in my trusted loations).

Given that I do not experience the same problem when I open Excel manually I assume it must be how I am automating excel:


    mExcel = New Excel.Application
    mExcel.EnableEvents = True
    mExcel.Visible = True
    mExcel.Application.DisplayAlerts = FalseCatch ex As Exception
    WriteToLog("Could not start Excel : " & ex.Message)


I also have the EnableEvents property of the mExcel object set to True.

Any help would be greatly appreciated - I have run in to any number of problems trying to automate this process in Excel and each time I manage to work around one issue another rears it's head!

When i try to open a log file on an Apache server, I can't bypass the username/password dialog box. I've tried the http://username:password@www.example.com syntax, but it still kicks up the dialog box. Anyone know how to over-ride that?

One of my SharePoint sites has an "Active" and an "Archived" document library. The Active document library contains folders which in turn contain Word and Excel documents. When the users are done with a particular folder, I have some code that moves the folder (and all contained documents) from the Active document library to the Archived document library.

Normally this runs fine and the call to SPFolder.MoveTo() moves the folder and all its contents without a hitch. The problem occurs when one of the users still has one of the Word or Excel documents open for editing on their desktop. When this happens, the MoveTo() call for the folder generates an error because one of the files inside the folder is "locked for editing". Here's the error I get:

Error: The file "http://XXXXX/ProposalOverheadCost.xlsx" is checked out or locked for editing by DOMAIN\user1.

Is there any way to programmatically check if a document in a document library is currently open/locked for editing by a user? That way I could avoid trying to move the folder until I've ensured that all Word and Excel documents inside it are closed. (Note: our users don't check the files out, they simply open them for editing)

All help is appreciated!




Is there anyway to show application bar's menuitems programmatically?

I want to simulate when the user taps on ... at application bar.



Does someone one as a piece of code to open a WorkItem programmatically into Team Explorer. I do have access to the WorkItem object.


Hi, I am trying to switch projects programmatically; all attempts have failed.


Calls to :  ProjectApplication.ActiveProject return a "Invalid type" even after I have specifically type cast my object.

The user has two or more projects open and I want to switch to a specific on, any clues ?



I need my application to be able to popup the Windows Services window on the click of a button. Any idea how could this be done?



It is possible to start SQL Server Management Studio and specify a data source, database, user id, and password on the command line.  When SSMS has loaded, object explorer has an open connection to the specified database.  

Now my user wants to be able to connect to a second database through my C# application.  Is there any way I can send a command to the running instance of SSMS to open a second connection in the object explorer to this second database?  If so how do I do that?


It is possible to start SQL Server Management Studio and specify a data source, database, user id, and password on the command line.  When SSMS has loaded, object explorer has an open connection to the specified database.  

Now my user wants to be able to connect to a second database through my C# application.  Is there any way I can send a command to the running instance of SSMS to open a second connection in the object explorer to this second database?  If so how do I do that?



In C# I am trying to open a document programatically, alter the meta data within the document and then save it.  I have two issues:

1.  If the "ReadOnlyRecommended" flag is checked, then a pop-up Save-As dialog appears which is not what I want.  I want to Open the document always writeable even if this flag is checked.

2.  If ShowRevisions is true then I want to overwrite it to false so that when the document is saved, it shows the final revision with No markup.

We are currently using the Office11 PIA, .NET 3.5, and word 2003.

Here is some sample code:



(WordDocument wordDocument = wordApplication.Open(WorkingFile))







I am doing an application in which i need to open an inbox and sent items folder in windows mobile using c#.

Inbox folder is opened by using this code :

 Process.Start(@"\Windows\tmail.exe", "");

Similar like this i need to open Sent Items folder in ppc.

Can any one help me.





In VB.net I have a Form , textbox and Commant Button,

In textbox I have entered path e.g "C:\Temp\Temp1"

When i click the command button the location "C:\Temp\Temp1" should get opened in windows explorer.

Thanks in Advance



I am using a CDialog class for showing a normal dialog, but I need that the language of this windows will be always in everyitems, also the close button on the top right corner of the dialog, because when i run my app on a O.S with native English languague, the tooltip of this button shows like "CLOSE".


I appreciate your help.



Christian Rojas




I'm implementing a language service and want to show a QuickInfo or DataTip in DebugMode but I don't know how to implement this feature?!

I've enabled the QuickInfo and Codesense property and the method GetDataTipText in my AuthoringScope class is called. But what is the next step?


Visual Studio 2010


I want to set Validation ToolTip for TextBox only when the user press submit button. How to do this.




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure