Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Other versions are also available for the following:
.NET Framework Class Library for Silverlight
ToolTip Class
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Represents a control that creates a pop-up window that displays information for an element in the UI.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)

Visual Basic (Declaration)
<TemplatePartAttribute(Name := "Normal State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "RootElement", Type := GetType(FrameworkElement))> _
<TemplatePartAttribute(Name := "Visible State", Type := GetType(Storyboard))> _
Public Class ToolTip _
    Inherits ContentControl
Visual Basic (Usage)
Dim instance As ToolTip
C#
[TemplatePartAttribute(Name = "Normal State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "RootElement", Type = typeof(FrameworkElement))]
[TemplatePartAttribute(Name = "Visible State", Type = typeof(Storyboard))]
public class ToolTip : ContentControl
Visual C++
[TemplatePartAttribute(Name = L"Normal State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = L"RootElement", Type = typeof(FrameworkElement))]
[TemplatePartAttribute(Name = L"Visible State", Type = typeof(Storyboard))]
public ref class ToolTip : public ContentControl
JScript
public class ToolTip extends ContentControl

You use a ToolTip control to provide information to the user. For example, you can use a ToolTip to provide the name of a Button. The content of a ToolTip control can vary from a simple text string to more complex content, such as a StackPanel that has embedded text and images. The content of a ToolTip cannot receive focus.

The properties of the ToolTip class are used to define the position and behavior of the tooltip. In addition, the ToolTipService class provides attached properties to set timing behavior. These properties are not included in the ToolTip class, but can be used to control its behavior.

Some controls lack a ToolTip property, such as TextBox and TextBlock. To add a ToolTip to these controls, you can use the ToolTip attached property. For more information, see ToolTipService.

The following XAML demonstrates basic tooltips, and a few advanced properties for timing and placement.

<UserControl x:Class="ToolTipExample.Page"
        xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:control="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
        Width="400"
        Height="300"
        >

    <Canvas x:Name="LayoutRoot" Background="White">
        <TextBlock Text="ToolTip Demonstration" Margin="0,20,10,20"
            FontFamily="Verdana" FontSize="18" FontWeight="Bold"
            Foreground="#FF5C9AC9" Canvas.Left="20" Canvas.Top="0"/>

        <!-- A button with a simple ToolTip. -->
        <Button x:Name="button1" Canvas.Top="60" Canvas.Left="20" 
                Content="Button with a simple ToolTip." 
                Height="100" Width="300">
            <Button.ToolTip>
                <ToolTip Content="This is an example ToolTip." />
            </Button.ToolTip>
        </Button>

        <!-- A TextBlock with a simple ToolTip. -->
        <!-- TextBlock and TextBox have to use this syntax. -->
        <TextBlock Text="TextBlock with a ToolTip." 
                   Canvas.Top="190" Canvas.Left="20" >
            <control:ToolTipService.ToolTip > 
                <ToolTip Content="This is a second example ToolTip." />
            </control:ToolTipService.ToolTip>
        </TextBlock>

        <!-- A button whose ToolTip appears far away from the mouse pointer. -->
        <Button x:Name="button2" Canvas.Top="60" Canvas.Left="340" 
                Content="Button with an offset ToolTip." Height="100" Width="300" >
            <Button.ToolTip>
                <ToolTip Content="This is a third example ToolTip." 
                                 HorizontalOffset="20"
                                 VerticalOffset="30"/>                                 
            </Button.ToolTip>
        </Button>

        <!-- A button whose ToolTip appears after five seconds and disappears again quickly. -->
        <Button x:Name="button3" Canvas.Top="290" Canvas.Left="20" 
                                 Content="Button with a ToolTip that appears after five seconds and disappears quickly." Height="100" Width="300" 
                                 control:ToolTipService.InitialShowDelay="5000"
                                 control:ToolTipService.ShowDuration="500"
                                 control:ToolTipService.BetweenShowDelay="5000"
                                 TextWrapping="Wrap">
            <Button.ToolTip>
                <ToolTip Content="This is a fourth example ToolTip." 
                                 />
            </Button.ToolTip>
        </Button>

    </Canvas>
</UserControl>

Run this sample.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker