ToolTip Class

Definition

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

[System.Windows.Localizability(System.Windows.LocalizationCategory.ToolTip)]
public class ToolTip : System.Windows.Controls.ContentControl
Inheritance
Derived
Attributes

Inherited Members

System.Object

System.Windows.Controls.ContentControl

System.Windows.Controls.Control

System.Windows.DependencyObject

System.Windows.FrameworkElement

System.Windows.Media.Visual

System.Windows.Threading.DispatcherObject

System.Windows.UIElement

Examples

The following examples shows how to define a tooltip control for a TextBox element.

The following example shows how to define a tooltip by assigning text to the ToolTip property.

<TextBox HorizontalAlignment="Left">TextBox with ToolTip
  <TextBox.ToolTip>
    <TextBlock>Useful information goes here.</TextBlock>
  </TextBox.ToolTip>
</TextBox>

The following example shows how to define a tooltip by assigning a ToolTip object to the ToolTip property.

<TextBox HorizontalAlignment="Left">ToolTip with non-text content
  <TextBox.ToolTip>
    <ToolTip>
      <DockPanel Width="50" Height="70">
        <Image Source="data\flower.jpg"/>
        <TextBlock>Useful information goes here.</TextBlock>
      </DockPanel>
    </ToolTip>
  </TextBox.ToolTip>
</TextBox>

The following example uses code to generate a ToolTip object. The example creates a ToolTip (tt) and associates it with a Button.

button = new Button();
button.Content = "Hover over me.";
tt = new ToolTip();
tt.Content = "Created with C#";
button.ToolTip = tt;
cv2.Children.Add(button);
button = New Button()
button.Content = "Hover over me."
tt = New ToolTip()
tt.Content = "Created with Visual Basic"
button.ToolTip = tt
cv2.Children.Add(button)

Remarks

A ToolTip is a ContentControl, which means that it can contain a single object of any type (such as a string, an image, or a panel). For more information, see the ContentControl class.

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 or a ToolBar in a ToolBarTray. 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.

A ToolTip control cannot have a parent. For example, you cannot set the Content property of a Button to a ToolTip Instead, assign a ToolTip to the FrameworkContentElement.ToolTip and FrameworkElement.ToolTip properties.

You can use a ToolTip on multiple elements by defining a ToolTip in a ResourceDictionary.

The properties of the ToolTip class are used to define the position and behavior of the tooltip. Many of these properties are also defined in the ToolTipService class. If the value of one of these properties is specified by both the ToolTip property and the ToolTipService attached property, the value of the ToolTipService property is used. In addition, the ToolTipService class provides properties to set timing behavior. These attached properties are not included in the ToolTip class but can be used by the control.

Customizing the ToolTip Control

To apply the same property settings to multiple ToolTip controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the ToolTip, see ToolTip Styles and Templates.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

Note

Setting a visual property will only have an effect if that property is both present in ToolTip control's default template and is set by using a . You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a ControlTemplate.

Constructors

ToolTip()

Initializes a new instance of the ToolTip class.

Fields

ClosedEvent

Identifies the Closed routed event.

CustomPopupPlacementCallbackProperty

Identifies the CustomPopupPlacementCallback dependency property.

HasDropShadowProperty

Identifies the HasDropShadow dependency property.

HorizontalOffsetProperty

Identifies the HorizontalOffset dependency property.

IsOpenProperty

Identifies the IsOpen dependency property.

OpenedEvent

Identifies the Opened routed event.

PlacementProperty

Identifies the Placement dependency property.

PlacementRectangleProperty

Identifies the PlacementRectangle dependency property.

PlacementTargetProperty

Identifies the PlacementTarget dependency property.

StaysOpenProperty

Identifies the StaysOpen dependency property.

VerticalOffsetProperty

Identifies the VerticalOffset dependency property.

Properties

CustomPopupPlacementCallback

Gets or sets the delegate handler method to use to position the ToolTip.

HasDropShadow

Gets or sets a value that indicates whether the control has a drop shadow.

HorizontalOffset

Get or sets the horizontal distance between the target origin and the popup alignment point.

IsOpen

Gets or sets a value that indicates whether a ToolTip is visible.

Placement

Gets or sets the orientation of the ToolTip control when it opens, and specifies how the ToolTip control behaves when it overlaps screen boundaries.

PlacementRectangle

Gets or sets the rectangular area relative to which the ToolTip control is positioned when it opens.

PlacementTarget

Gets or sets the UIElement relative to which the ToolTip is positioned when it opens.

StaysOpen

Gets or sets a value that indicates whether an open ToolTip remains open until the user clicks the mouse when the mouse is not over the ToolTip.

VerticalOffset

Get or sets the vertical distance between the target origin and the popup alignment point.

Methods

OnClosed(RoutedEventArgs)

Responds to the Closed event.

OnContentChanged(Object, Object)

Called when the Content property changes.

OnCreateAutomationPeer()

Creates the implementation of AutomationPeer for the ToolTip control.

OnOpened(RoutedEventArgs)

Responds to the Opened event.

OnVisualParentChanged(DependencyObject)

Responds to a change in the visual parent of a ToolTip.

Events

Closed

Occurs when a ToolTip is closed and is no longer visible.

Opened

Occurs when a ToolTip becomes visible.