ToolTipService ToolTipService ToolTipService Class

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

Syntax

Declaration

public sealed class ToolTipServicepublic sealed class ToolTipServicePublic NotInheritable Class ToolTipService

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(DependencyObject) and SetPlacement(DependencyObject, PlacementMode) methods support and provide the equivalent code-only support for PlacementProperty. Alternatively, you can use the dependency property system to get or set the value of the attached property. Call GetValue(DependencyProperty) or SetValue(DependencyProperty, Object), 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 ToolTipProperty attached property to assign the ToolTip to an owner. In code, use the SetToolTip(DependencyObject, Object) 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 PlacementProperty 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.

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>

Properties summary

Identifies the PlacementProperty XAML attached property.

Identifies the PlacementTargetProperty XAML attached property.

Identifies the ToolTipProperty XAML attached property.

Methods summary

Gets the PlacementProperty XAML attached property value for the specified target element.

Gets the PlacementTargetProperty XAML attached property value for the specified target element.

Gets the value of the ToolTipProperty XAML attached property for an object.

Sets the PlacementProperty XAML attached property value for the specified target element.

Sets the PlacementTargetProperty XAML attached property value for the specified target element.

Sets the value of the ToolTipProperty XAML attached property.

Properties

  • PlacementProperty
    PlacementProperty
    PlacementProperty
    PlacementProperty

    Identifies the PlacementProperty XAML attached property.

    public static DependencyProperty PlacementProperty { get; }public static DependencyProperty PlacementProperty { get; }Public Static ReadOnly Property PlacementProperty As DependencyPropertypublic static DependencyProperty PlacementProperty { get; }

    Property Value

  • PlacementTargetProperty
    PlacementTargetProperty
    PlacementTargetProperty
    PlacementTargetProperty

    Identifies the PlacementTargetProperty XAML attached property.

    public static DependencyProperty PlacementTargetProperty { get; }public static DependencyProperty PlacementTargetProperty { get; }Public Static ReadOnly Property PlacementTargetProperty As DependencyPropertypublic static DependencyProperty PlacementTargetProperty { get; }

    Property Value

  • ToolTipProperty
    ToolTipProperty
    ToolTipProperty
    ToolTipProperty

    Identifies the ToolTipProperty XAML attached property.

    public static DependencyProperty ToolTipProperty { get; }public static DependencyProperty ToolTipProperty { get; }Public Static ReadOnly Property ToolTipProperty As DependencyPropertypublic static DependencyProperty ToolTipProperty { get; }

    Property Value

Methods

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

    Gets the PlacementProperty 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 PlacementModepublic static PlacementMode GetPlacement(DependencyObject element)

    Parameters

    Returns

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

    Gets the PlacementTargetProperty 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 UIElementpublic static UIElement GetPlacementTarget(DependencyObject element)

    Parameters

    Returns

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

    Gets the value of the ToolTipProperty XAML attached property for an object.

    public static object GetToolTip(DependencyObject element)public static object GetToolTip(DependencyObject element)Public Static Function GetToolTip(element As DependencyObject) As objectpublic static object GetToolTip(DependencyObject element)

    Parameters

    Returns

    • object
      object
      object

      The object's tooltip content.

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

    Sets the PlacementProperty 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 voidpublic static void SetPlacement(DependencyObject element, PlacementMode value)

    Parameters

    Remarks

    This method supports the PlacementProperty 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 PlacementTargetProperty attached property.

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

    Sets the PlacementTargetProperty 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 voidpublic static void SetPlacementTarget(DependencyObject element, UIElement value)

    Parameters

    Remarks

    This method supports the PlacementTargetProperty 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 PlacementTargetProperty 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 ToolTipProperty XAML attached property.

    public static void SetToolTip(DependencyObject element, Object value)public static void SetToolTip(DependencyObject element, Object value)Public Static Function SetToolTip(element As DependencyObject, value As Object) As voidpublic static void SetToolTip(DependencyObject element, Object value)

    Parameters

    Remarks

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

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll