Home  separator  Controls  separator  ToolTips
Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  


ToolTips in WPF

 
<Button Content="Submit">
    <Button.ToolTip>
        <ToolTip>
            <StackPanel>
                <TextBlock FontWeight="Bold">Submit Request</TextBlock>
                <TextBlock>Submits the request to the server.</TextBlock>
            </StackPanel>
        </ToolTip>
    </Button.ToolTip>
</Button>
 
 

How to show ToolTips on disabled controls

When you disable a control with IsEnabled=False the tooltip does not show anymore. If you want to have the tooltip appear anyway you have to set the attaached property ToolTipService.ShowOnDisabled to True.

 
<Button IsEnabled="False" 
        ToolTip="Saves the current document"
        ToolTipService.ShowOnDisabled="True"
        Content="Save">
</Button>
 
 

How to change the show duration of a ToolTip

The static class ToolTipService allows you to modify the show duration of the tooltip

 
<Button ToolTip="Saves the current document"
        ToolTipService.ShowDuration="20"
        Content="Save">
</Button>
 
 




Last modified: 2009-06-27 18:48:48
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
DON
Commented on 18.June 2009
Hun too Yae baat hai
Tormentor
Commented on 26.June 2009
Hi Christian, Can we modify the tooltip content and make like a content presenter, like office 2007 tooltips for an example(Header, Description, image, etc...)?
Sumit
Commented on 12.July 2009
Nice tutorial , good that it includes tooltipservice : http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltipservice(VS.95).aspx

Bolshoi Booze
Commented on 7.September 2009
Hi Christian

Is it possible to have something like below:

<Style TargetType="{x:Type ...}">
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition .. />
<Condition .. />
</MultiDataTrigger.Conditions>
<Setter Property="ToolTip>
<Setter.Value>
<Grid>
...[Custom Content such as images, textblocks etc]...
</Grid>
</Setter.Value>
</Setter>
</MultiDataTrigger>
</Style>


When I do this I get a below exception:

Exception Cannot add content of type 'System.Windows.Controls.Grid' to an object of type 'System.Object'.

Thanks
Bolshoi Booze
Commented on 7.September 2009
Hi Christian

Is it possible to have something like below:

<Style TargetType="{x:Type ...}">
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition .. />
<Condition .. />
</MultiDataTrigger.Conditions>
<Setter Property="ToolTip>
<Setter.Value>
<Grid>
...[Custom Content such as images, textblocks etc]...
</Grid>
</Setter.Value>
</Setter>
</MultiDataTrigger>
</Style>


When I do this I get a below exception:

Exception Cannot add content of type 'System.Windows.Controls.Grid' to an object of type 'System.Object'.

Thanks
Christian Moser
Commented on 8.September 2009
Hi Bolshoi,
there are two problems in your approach. The property "tooltip" that you are trying to set requires an object of type tooltip. So you need to warp your <Grid> into a <Tooltip> element.
The second problem is that a style is something like a singleton. It's only created once and applied multiple times. This means that if you include wpf elements in a style you have to add the x:Shared="False" attribute to the style.
I hope this helps you.

Greetings
Christian
Rajagopal
Commented on 3.December 2009
simple and working
M Islam
Commented on 12.January 2010
Great Work !!!
Jawahar
Commented on 16.January 2010
Great, its simple and easy to learn....
Heinzi
Commented on 17.February 2010
ToolTipService.ShowDuration is in Milliseconds, so "20" might not be the best example.
Victor
Commented on 9.April 2010
You are Man!
CoolDev
Commented on 20.May 2010
Suoerb Piece of Code
Daniel
Commented on 12.August 2010
I dont have visual studio in this computer so I have to ask... Can I show an image inside the tooltip? If I add an Image tag inside the StackPanel should work??? The code should be like this:

<Button Content="Submit">
<Button.ToolTip>
<ToolTip>
<StackPanel>
<image ... />
<TextBlock FontWeight="Bold">Submit Request</TextBlock>
<TextBlock>Submits the request to the server.</TextBlock>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>

Im ok or is another way to have an image in the tooltip?
someone
Commented on 21.August 2010
Hi
How can I set this tooltip (with stackpanel etc) in style file?
I made my style for textbox

<Style x:Key="DefaultStyle" TargetType="{x:Type TextBox}">
<Setter Property="FontFamily" Value="Tahoma"/>
<Setter Property="FontSize" Value="15"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="BorderBrush" Value="#A9C2DE"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Background">

<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1" >
<GradientStop Color="#CDE1F7" Offset="0.01"/>
<GradientStop Color="#DFECFA" Offset="0.8" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<TextBlock Text="Nice toolbox"/>
<TextBlock Text="Nice tooltip"/>
</StackPanel>
</Setter.Value>

</Setter>
</Style>

But I get xaml parse exception error if I use this style. Is it possible to set this tooltip in style file?
durga
Commented on 14.September 2010
Nice Explanation..
Girish Jain
Commented on 23.October 2010
Brevity is the soul of wit!! To the point and perfect sample
El Matador
Commented on 22.January 2011
I love this, great tip. Nice example. Thanks!
Alex
Commented on 28.January 2011
I'm also interested in styled tooltips like commentator from "21.August 2010"
Aldha Qhurbaini
Commented on 29.January 2011
Nice article, simple and good sample for my project. AH
Kaustubh...
Commented on 24.March 2011
How to apply image to button.
Sanjay Patolia
Commented on 29.March 2011
Nice sample
YuZhoufeng
Commented on 1.April 2011
Wonderful!
Tejas
Commented on 23.April 2011
Hey really grt ... Thanks a lot
Naren
Commented on 4.May 2011
Hi Christian

All your examples are really great.I want to know whether there is any control to display text along with images in between(images such as graphs and diagrams). If there is no control, then please mail me how to create a control to satisfy this. If possible mail the code for creating such a control.

Thanks
Terry
Commented on 30.June 2011
Hi Christian, is it possible to put clickable button inside tooltip?
This xaml displays button but you can't click on it.

Thanks

Terry

Ex:
&lt;ComboBox.ToolTip&gt;
&lt;ToolTip Placement=&quot;Center&quot; Focusable=&quot;True&quot; StaysOpen=&quot;True&quot;&gt;
&lt;Button Content=&quot;button inside tool tip&quot; Focusable=&quot;True&quot; Click=&quot;Button_Click_1&quot; /&gt;
&lt;/ToolTip&gt;
&lt;/ComboBox.ToolTip&gt;

Name
E-Mail (optional)
Comment