Files
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

5.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Position a ToolTip 03/30/2017
csharp
vb
ToolTip control [WPF], positioning
positioning ToolTip controls [WPF]
cddf3757-9e5f-4ce3-a6eb-44489cf3804a

How to: Position a ToolTip

This example shows how to specify the position of a tooltip on the screen.

Example

You can position a tooltip by using a set of five properties that are defined in both the xref:System.Windows.Controls.ToolTip and xref:System.Windows.Controls.ToolTipService classes. The following table shows these two sets of five properties and provides links to their reference documentation according to class.

Corresponding tooltip properties according to class

xref:System.Windows.Controls.ToolTip?displayProperty=nameWithType class properties xref:System.Windows.Controls.ToolTipService?displayProperty=nameWithType class properties
xref:System.Windows.Controls.ToolTip.Placement%2A?displayProperty=nameWithType xref:System.Windows.Controls.ToolTipService.Placement%2A?displayProperty=nameWithType
xref:System.Windows.Controls.ToolTip.PlacementTarget%2A?displayProperty=nameWithType xref:System.Windows.Controls.ToolTipService.PlacementTarget%2A?displayProperty=nameWithType
xref:System.Windows.Controls.ToolTip.PlacementRectangle%2A?displayProperty=nameWithType xref:System.Windows.Controls.ToolTipService.PlacementRectangle%2A?displayProperty=nameWithType
xref:System.Windows.Controls.ToolTip.HorizontalOffset%2A?displayProperty=nameWithType xref:System.Windows.Controls.ToolTipService.HorizontalOffset%2A?displayProperty=nameWithType
xref:System.Windows.Controls.ToolTip.VerticalOffset%2A?displayProperty=nameWithType xref:System.Windows.Controls.ToolTipService.VerticalOffset%2A?displayProperty=nameWithType

If you define the contents of a tooltip by using a xref:System.Windows.Controls.ToolTip object, you can use the properties of either class; however, the xref:System.Windows.Controls.ToolTipService properties take precedence. Use the xref:System.Windows.Controls.ToolTipService properties for tooltips that are not defined as xref:System.Windows.Controls.ToolTip objects.

The following illustrations show how to position a tooltip by using these properties. Although, the Extensible Application Markup Language (XAML) examples in these illustrations show how to set the properties that are defined by the xref:System.Windows.Controls.ToolTip class, the corresponding properties of the xref:System.Windows.Controls.ToolTipService class follow the same layout rules. For more information about the possible values for the Placement property, see Popup Placement Behavior.

The following image shows tooltip placement by using the Placement property:

Diagram showing ToolTip placement by using the Placement property.

The following image shows tooltip placement by using the Placement and PlacementRectangle properties:

Diagram showing ToolTip placement by using a PlacementRectangle property.

The following image shows tooltip placement by using the Placement, PlacementRectangle, and Offset properties:

Diagram showing ToolTip placement by using the Offset property.

The following example shows how to use the xref:System.Windows.Controls.ToolTip properties to specify the position of a tooltip whose content is a xref:System.Windows.Controls.ToolTip object.

[!code-xamlToolTipService#ToolTip]

[!code-csharpToolTipService#ToolTipCode] [!code-vbToolTipService#ToolTipCode]

The following example shows how to use the xref:System.Windows.Controls.ToolTipService properties to specify the position of a tooltip whose content is not a xref:System.Windows.Controls.ToolTip object.

[!code-xamlToolTipService#NoToolTip]

[!code-csharpToolTipService#NoToolTipCode] [!code-vbToolTipService#NoToolTipCode]

See also