ToolTipService ToolTipService ToolTipService ToolTipService Class

Definition

Represents a service that provides static methods to display a ToolTip.

public : sealed class ToolTipService : IToolTipServicepublic sealed class ToolTipService : IToolTipServicePublic NotInheritable Class ToolTipService Implements IToolTipService// This API is not available in Javascript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following code example demonstrates the placement modes for a ToolTip.

<StackPanel Margin="120" >
    <TextBlock Text="ToolTip Control" Margin="5" 
               Style="{StaticResource HeaderTextStyle}" />
    <TextBlock Text="Hover over an item to see its ToolTip: " 
               Style="{StaticResource ItemTextStyle}" Margin="10" />
    <ListBox Width="100">
        <ListBoxItem Content="Left" 
            ToolTipService.ToolTip="ToolTip to the left." 
            ToolTipService.Placement="Left" />
        <ListBoxItem Content="Right" 
            ToolTipService.ToolTip="ToolTip to the right." 
            ToolTipService.Placement="Right" />
        <ListBoxItem Content="Top" 
            ToolTipService.ToolTip="ToolTip at the top." 
            ToolTipService.Placement="Top" />
        <ListBoxItem Content="Bottom" 
            ToolTipService.ToolTip="ToolTip at the bottom." 
            ToolTipService.Placement="Bottom"/>
        <ListBoxItem Content="Mouse" 
            ToolTipService.ToolTip="ToolTip based on the cursor position." 
            ToolTipService.Placement="Mouse"/>
    </ListBox>
</StackPanel>

Remarks

ToolTipService XAML attached properties

ToolTipService is the host service class for several Extensible Application Markup Language (XAML) attached properties. The purpose of these attached properties is to enable target elements to qualify how they should be positioned relative to placement target elements.

ToolTipService provides the following attached properties for Extensible Application Markup Language (XAML) usage:

In order to support Extensible Application Markup Language (XAML) processor access to the attached properties, and also to expose equivalent get and set operations to code, each Extensible Application Markup Language (XAML) attached property has a pair of Get and Set accessor methods. For example, the GetPlacement and SetPlacement methods support and provide the equivalent code-only support for ToolTipService.Placement. Alternatively, you can use the dependency property system to get or set the value of the attached property. Call GetValue or SetValue, passing the arguments of the dependency property identifier to set, and a reference to the target object on which to get or set the value.

A ToolTip must be assigned to another UI element that is its owner. In Extensible Application Markup Language (XAML), use the ToolTipService.Tooltip attached property to assign the ToolTip to an owner. In code, use the ToolTipService.SetToolTip method to assign the ToolTip to an owner.

Placement

By default, a ToolTip is displayed centered above the pointer. The placement is not constrained by the app window, so the ToolTip might be displayed partially or completely outside of the app window bounds.

If a ToolTip obscures the content it is referring to, you can adjust it's placement. Use the ToolTipService.Placement attached property to place the ToolTip above, below, left, or right of the pointer.

Notes for previous versions

Windows 8.x ToolTip is intended only for use in Windows. The ToolTip type is available in Windows Phone projects for compatibility with universal project templates, but the ToolTip is not shown in the Windows Phone UI.

ToolTip is displayed only within the bounds of the app window. It's placement might be adjusted to stay within those bounds.

Properties

PlacementProperty PlacementProperty PlacementProperty PlacementProperty

Identifies the ToolTipService.Placement XAML attached property.

public : static DependencyProperty PlacementProperty { get; }public static DependencyProperty PlacementProperty { get; }Public Static ReadOnly Property PlacementProperty As DependencyProperty// This API is not available in Javascript.

PlacementTargetProperty PlacementTargetProperty PlacementTargetProperty PlacementTargetProperty

Identifies the ToolTipService.PlacementTarget XAML attached property.

public : static DependencyProperty PlacementTargetProperty { get; }public static DependencyProperty PlacementTargetProperty { get; }Public Static ReadOnly Property PlacementTargetProperty As DependencyProperty// This API is not available in Javascript.

ToolTipProperty ToolTipProperty ToolTipProperty ToolTipProperty

Identifies the ToolTipService.ToolTip XAML attached property.

public : static DependencyProperty ToolTipProperty { get; }public static DependencyProperty ToolTipProperty { get; }Public Static ReadOnly Property ToolTipProperty As DependencyProperty// This API is not available in Javascript.

Methods

GetPlacement(DependencyObject) GetPlacement(DependencyObject) GetPlacement(DependencyObject) GetPlacement(DependencyObject)

Gets the ToolTipService.Placement XAML attached property value for the specified target element.

public : static PlacementMode GetPlacement(DependencyObject element)public static PlacementMode GetPlacement(DependencyObject element)Public Static Function GetPlacement(element As DependencyObject) As PlacementMode// This API is not available in Javascript.
Parameters
element
DependencyObject DependencyObject DependencyObject DependencyObject

The target element for the attached property value.

Returns

The relative position of the specified tooltip.

GetPlacementTarget(DependencyObject) GetPlacementTarget(DependencyObject) GetPlacementTarget(DependencyObject) GetPlacementTarget(DependencyObject)

Gets the ToolTipService.PlacementTarget XAML attached property value for the specified target element.

public : static UIElement GetPlacementTarget(DependencyObject element)public static UIElement GetPlacementTarget(DependencyObject element)Public Static Function GetPlacementTarget(element As DependencyObject) As UIElement// This API is not available in Javascript.
Parameters
element
DependencyObject DependencyObject DependencyObject DependencyObject

The target element for the attached property value.

Returns

The visual element that the tooltip is positioned relative to.

GetToolTip(DependencyObject) GetToolTip(DependencyObject) GetToolTip(DependencyObject) GetToolTip(DependencyObject)

Gets the value of the ToolTipService.ToolTip XAML attached property for an object.

public : static PlatForm::Object GetToolTip(DependencyObject element)public static object GetToolTip(DependencyObject element)Public Static Function GetToolTip(element As DependencyObject) As object// This API is not available in Javascript.
Parameters
element
DependencyObject DependencyObject DependencyObject DependencyObject

The object from which the property value is read.

Returns
PlatForm::Object object object object

The object's tooltip content.

SetPlacement(DependencyObject, PlacementMode) SetPlacement(DependencyObject, PlacementMode) SetPlacement(DependencyObject, PlacementMode) SetPlacement(DependencyObject, PlacementMode)

Sets the ToolTipService.Placement XAML attached property value for the specified target element.

public : static void SetPlacement(DependencyObject element, PlacementMode value)public static void SetPlacement(DependencyObject element, PlacementMode value)Public Static Function SetPlacement(element As DependencyObject, value As PlacementMode) As void// This API is not available in Javascript.
Parameters
element
DependencyObject DependencyObject DependencyObject DependencyObject

The target element for the attached property value.

value
PlacementMode PlacementMode PlacementMode PlacementMode

One of the PlacementMode values, which specifies where the tooltip should appear relative to the control that is the placement target.

Remarks

This method supports the ToolTipService.Placement attached property usage for Extensible Application Markup Language (XAML). The target element is not necessarily a ToolTip, it might be an element that owns an inferred tooltip through usage of ToolTipService APIs. Also, the target element is not necessarily the final placement target, because that can be reset by setting the ToolTipService.PlacementTarget attached property.

SetPlacementTarget(DependencyObject, UIElement) SetPlacementTarget(DependencyObject, UIElement) SetPlacementTarget(DependencyObject, UIElement) SetPlacementTarget(DependencyObject, UIElement)

Sets the ToolTipService.PlacementTarget XAML attached property value for the specified target element.

public : static void SetPlacementTarget(DependencyObject element, UIElement value)public static void SetPlacementTarget(DependencyObject element, UIElement value)Public Static Function SetPlacementTarget(element As DependencyObject, value As UIElement) As void// This API is not available in Javascript.
Parameters
element
DependencyObject DependencyObject DependencyObject DependencyObject

The target element for the attached property value.

value
UIElement UIElement UIElement UIElement

The visual element that should be the placement target for the tooltip.

Remarks

This method supports the ToolTipService.PlacementTarget attached property usage for Extensible Application Markup Language (XAML). The value for element is not necessarily a ToolTip, it might be an element that owns an inferred tooltip through usage of ToolTipService APIs. You can use the ToolTipService.PlacementTarget attached property to set the placement target to be different than the element that owns the ToolTip for purposes of UI behavior and built-in PointerEntered / PointerExited handling. This enables controls to act like a unit for tooltip display, so that the tooltip from one control does not obscure an important part of a related control when it displays.

SetToolTip(DependencyObject, Object) SetToolTip(DependencyObject, Object) SetToolTip(DependencyObject, Object) SetToolTip(DependencyObject, Object)

Sets the value of the ToolTipService.ToolTip XAML attached property.

public : static void SetToolTip(DependencyObject element, PlatForm::Object value)public static void SetToolTip(DependencyObject element, Object value)Public Static Function SetToolTip(element As DependencyObject, value As Object) As void// This API is not available in Javascript.
Parameters
element
DependencyObject DependencyObject DependencyObject DependencyObject

The object to set tooltip content on.

value
PlatForm::Object Object Object Object

The value to set for tooltip content.

Remarks

A ToolTip must be assigned to another UI element that is its owner. In Extensible Application Markup Language (XAML), use the ToolTipService.Tooltip attached property to assign the ToolTip to an owner. In code, use the ToolTipService.SetToolTip method to assign the ToolTip to an owner.

See ToolTipService.ToolTip or ToolTip to learn more about the object content or text that is appropriate to use as tooltip content.

See Also