ToolTipService 类

定义

表示一项服务,该服务提供用于控制工具提示的显示和行为的属性和事件。Represents a service that provides properties and events to control the display and behavior of tooltips.

public ref class ToolTipService abstract sealed
public static class ToolTipService
type ToolTipService = class
Public Class ToolTipService
继承
ToolTipService

示例

下面的示例演示如何使用 ToolTipService 类指定工具提示的行为。The following example shows how the use the ToolTipService class to specify the behavior of a tooltip. 可以通过将 ToolTipService 类的属性直接附加到公开工具提示的元素来设置这些属性。You set the properties of the ToolTipService class by attaching them directly to the element that exposes the tooltip.

<Ellipse Height="25" Width="50" 
      Fill="Gray" 
      HorizontalAlignment="Left"
      ToolTipService.InitialShowDelay="1000"
      ToolTipService.ShowDuration="7000"
      ToolTipService.BetweenShowDelay="2000"
      ToolTipService.Placement="Right" 
      ToolTipService.PlacementRectangle="50,0,0,0"
      ToolTipService.HorizontalOffset="10" 
      ToolTipService.VerticalOffset="20"
      ToolTipService.HasDropShadow="false"
      ToolTipService.ShowOnDisabled="true" 
      ToolTipService.IsEnabled="true"
      ToolTipOpening="whenToolTipOpens"
      ToolTipClosing="whenToolTipCloses"
      >
  <Ellipse.ToolTip>
    <BulletDecorator>
      <BulletDecorator.Bullet>
        <Ellipse Height="10" Width="20" Fill="Blue"/>
      </BulletDecorator.Bullet>
      <TextBlock>Uses the ToolTipService class</TextBlock>
    </BulletDecorator>
  </Ellipse.ToolTip>
</Ellipse>

注解

通过设置 FrameworkContentElement.ToolTipFrameworkElement.ToolTip 属性为元素定义工具提示。You define a tooltip for an element by setting the FrameworkContentElement.ToolTip or FrameworkElement.ToolTip property. ToolTip 属性采用一个子级。The ToolTip property takes one child. 子字符串的内容可能会因简单文本字符串而异,而不是具有嵌入文本和 Image 元素的 StackPanelThe content of the child can vary from a simple text string to more complex content such as a StackPanel that has embedded text and Image elements.

可以将工具提示内容定义为 ToolTip 对象,但这不是必需的。You can define tooltip content as a ToolTip object, but this is not required. 如果不将 tooltip 内容定义为 ToolTip 对象,则可以使用 ToolTipService 属性来定位和自定义工具提示内容。When you do not define the tooltip content as a ToolTip object, you can use the ToolTipService properties to position and customize the tooltip content. ToolTipService 类的附加属性用于确定工具提示的位置、行为和外观。Attached properties of the ToolTipService class are used to determine the placement, behavior, and appearance of a tooltip. 这些属性是在定义工具提示的元素上设置的。These properties are set on the element that defines the tooltip.

ToolTip 类和 ToolTipService 类共享多个用于自定义工具提示的相同属性。The ToolTip class and the ToolTipService class share many of the same properties that are used to customize a tooltip. 如果同时设置了等效 ToolTipToolTipService 属性,ToolTipService 属性优先。If equivalent ToolTip and ToolTipService properties are both set, the ToolTipService property takes precedence. 例如,如果为 System.Windows.Controls.ToolTip 对象同时设置了 ToolTip.Placement 属性和 ToolTipService.Placement 属性,则使用 ToolTipService.Placement 属性的值。For example, if both the ToolTip.Placement property and the ToolTipService.Placement property are set for a System.Windows.Controls.ToolTip object, the value of the ToolTipService.Placement property is used.

以下 ToolTipService 时间属性仅针对 ToolTipService 类定义,由所有工具提示使用:The following ToolTipService timing properties are only defined for the ToolTipService class and are used by all tooltips:

有关如何处理在工具提示打开或关闭时发生的事件的信息,请参阅 ToolTipOpeningEventToolTipClosingEvent 字段。For information about how to handle the events that occur when the tooltip opens or closes, see the ToolTipOpeningEvent and ToolTipClosingEvent fields.

PlacementPlacementRectanglePlacementTargetHorizontalOffsetVerticalOffset 的行为类似于 Popup 类中具有相同名称的属性。Placement, PlacementRectangle, PlacementTarget, HorizontalOffset, and VerticalOffset behave similarly to the properties of the same name in the Popup class. 有关详细信息,请参阅 Popup 放置行为For more information, see Popup Placement Behavior.

字段

BetweenShowDelayProperty

标识 BetweenShowDelay 附加属性。Identifies the BetweenShowDelay attached property.

HasDropShadowProperty

标识 HasDropShadow 附加属性。Identifies the HasDropShadow attached property.

HorizontalOffsetProperty

标识 HorizontalOffset 附加属性。Identifies the HorizontalOffset attached property.

InitialShowDelayProperty

标识 InitialShowDelay 附加属性。Identifies the InitialShowDelay attached property.

IsEnabledProperty

标识 IsEnabled 附加属性。Identifies the IsEnabled attached property.

IsOpenProperty

标识 IsOpen 附加属性。Identifies the IsOpen attached property.

PlacementProperty

标识 Placement 附加属性。Identifies the Placement attached property.

PlacementRectangleProperty

标识 PlacementRectangle 附加属性。Identifies the PlacementRectangle attached property.

PlacementTargetProperty

标识 PlacementTarget 附加属性。Identifies the PlacementTarget attached property.

ShowDurationProperty

标识 ShowDuration 附加属性。Identifies the ShowDuration attached property.

ShowOnDisabledProperty

标识 ShowOnDisabled 附加属性。Identifies the ShowOnDisabled attached property.

ToolTipClosingEvent

标识由使用 ToolTipClosing 服务显示工具提示的对象公开的 ToolTipService 事件。Identifies the ToolTipClosing event that is exposed by objects that use the ToolTipService service to display tooltips.

ToolTipOpeningEvent

标识由使用 ToolTipOpening 服务显示工具提示的对象公开的 ToolTipService 事件。Identifies the ToolTipOpening event that is exposed by objects that use the ToolTipService service to display tooltips.

ToolTipProperty

标识 ToolTip 附加属性。Identifies the ToolTip attached property.

VerticalOffsetProperty

标识 VerticalOffset 附加属性。Identifies the VerticalOffset attached property.

附加属性

BetweenShowDelay

获取或设置当第二个工具提示在没有延迟的情况下显示时,两个工具提示的显示之间的最大时间。Gets or sets the maximum time between the display of two tooltips where the second tooltip appears without a delay.

HasDropShadow

获取或设置工具提示是否显示投影效果。Gets or sets whether the tooltip displays a drop shadow effect.

HorizontalOffset

获取或设置由 PlacementRectanglePlacementTarget 属性为工具提示指定的区域的左侧偏移量。Gets or sets the offset from the left of the area that is specified for the tooltip by the PlacementRectangle and PlacementTarget properties.

InitialShowDelay

获取或设置工具提示打开之前的时间长度。Gets or sets the length of time before a tooltip opens.

IsEnabled

获取或设置是否显示工具提示。Gets or sets whether a tooltip appears.

IsOpen

获取工具提示当前是否可见。Gets whether a tooltip is currently visible.

Placement

获取或设置工具提示在打开时的方向,并指定工具提示在与屏幕边界重叠时的行为方式。Gets or sets the orientation of the tooltip when it opens, and specifies how the tooltip behaves when it overlaps screen boundaries.

PlacementRectangle

获取或设置相对于其来放置工具提示的矩形区域。Gets or sets the rectangular area relative to which the tooltip is positioned.

PlacementTarget

获取或设置相对于其来放置工具提示的对象。Gets or sets the object relative to which the tooltip is positioned.

ShowDuration

获取或设置工具提示保持可见的时间。Gets or sets the amount of time that a tooltip remains visible.

ShowOnDisabled

获取或设置是否为未启用的对象显示工具提示。Gets or sets whether a tooltip appears for an object that is not enabled.

ToolTip

获取或设置工具提示的内容。Gets or sets the content of a tooltip.

VerticalOffset

获取或设置由 PlacementRectanglePlacementTarget 属性为工具提示指定的区域的顶部距离。Gets or sets the distance from the top of the area that is specified for the tooltip by the PlacementRectangle and PlacementTarget properties.

方法

AddToolTipClosingHandler(DependencyObject, ToolTipEventHandler)

ToolTipClosing 附加事件添加处理程序。Adds a handler for the ToolTipClosing attached event.

AddToolTipOpeningHandler(DependencyObject, ToolTipEventHandler)

ToolTipOpening 附加事件添加处理程序。Adds a handler for the ToolTipOpening attached event.

GetBetweenShowDelay(DependencyObject)

获取对象的 BetweenShowDelay 附加属性的值。Gets the value of the BetweenShowDelay attached property for an object.

GetHasDropShadow(DependencyObject)

获取对象的 HasDropShadow 附加属性的值。Gets the value of the HasDropShadow attached property for an object.

GetHorizontalOffset(DependencyObject)

获取对象的 HorizontalOffset 附加属性的值。Gets the value of the HorizontalOffset attached property for an object.

GetInitialShowDelay(DependencyObject)

获取对象的 InitialShowDelay 附加属性的值。Gets the value of the InitialShowDelay attached property for an object.

GetIsEnabled(DependencyObject)

获取对象的 IsEnabled 附加属性的值。Gets the value of the IsEnabled attached property for an object.

GetIsOpen(DependencyObject)

获取对象的 IsOpen 附加属性的值。Gets the value of the IsOpen attached property for an object.

GetPlacement(DependencyObject)

获取对象的 Placement 附加属性的值。Gets the value of the Placement attached property for an object.

GetPlacementRectangle(DependencyObject)

获取对象的 PlacementRectangle 附加属性的值。Gets the value of the PlacementRectangle attached property for an object.

GetPlacementTarget(DependencyObject)

获取对象的 PlacementTarget 附加属性的值。Gets the value of the PlacementTarget attached property for an object.

GetShowDuration(DependencyObject)

获取对象的 ShowDuration 附加属性的值。Gets the value of the ShowDuration attached property for an object.

GetShowOnDisabled(DependencyObject)

获取对象的 ShowOnDisabled 附加属性的值。Gets the value of the ShowOnDisabled attached property for an object.

GetToolTip(DependencyObject)

获取对象的 ToolTip 附加属性的值。Gets the value of the ToolTip attached property for an object.

GetVerticalOffset(DependencyObject)

获取对象的 VerticalOffset 附加属性的值。Gets the value of the VerticalOffset attached property for an object.

RemoveToolTipClosingHandler(DependencyObject, ToolTipEventHandler)

移除 ToolTipClosing 附加事件的处理程序。Removes a handler for the ToolTipClosing attached event.

RemoveToolTipOpeningHandler(DependencyObject, ToolTipEventHandler)

移除 ToolTipOpening 附加事件的处理程序。Removes a handler for the ToolTipOpening attached event.

SetBetweenShowDelay(DependencyObject, Int32)

设置对象的 BetweenShowDelay 附加属性的值。Sets the value of the BetweenShowDelay attached property for an object.

SetHasDropShadow(DependencyObject, Boolean)

设置对象的 HasDropShadow 附加属性的值。Sets the value of the HasDropShadow attached property for an object.

SetHorizontalOffset(DependencyObject, Double)

设置对象的 HorizontalOffset 附加属性的值。Sets the value of the HorizontalOffset attached property for an object.

SetInitialShowDelay(DependencyObject, Int32)

设置对象的 InitialShowDelay 附加属性的值。Sets the value of the InitialShowDelay attached property for an object.

SetIsEnabled(DependencyObject, Boolean)

设置对象的 IsEnabled 附加属性的值。Sets the value of the IsEnabled attached property for an object.

SetPlacement(DependencyObject, PlacementMode)

设置对象的 Placement 附加属性的值。Sets the value of the Placement attached property for an object.

SetPlacementRectangle(DependencyObject, Rect)

设置对象的 PlacementRectangle 附加属性的值。Sets the value of the PlacementRectangle attached property for an object.

SetPlacementTarget(DependencyObject, UIElement)

设置对象的 PlacementTarget 附加属性的值。Sets the value of the PlacementTarget attached property for an object.

SetShowDuration(DependencyObject, Int32)

设置对象的 ShowDuration 附加属性的值。Sets the value of the ShowDuration attached property for an object.

SetShowOnDisabled(DependencyObject, Boolean)

设置对象的 ShowOnDisabled 附加属性的值。Sets the value of the ShowOnDisabled attached property for an object.

SetToolTip(DependencyObject, Object)

设置对象的 ToolTip 附加属性的值。Sets the value of the ToolTip attached property for an object.

SetVerticalOffset(DependencyObject, Double)

设置对象的 VerticalOffset 附加属性的值。Sets the value of the VerticalOffset attached property for an object.

附加事件

ToolTipClosing

ToolTip 关闭时发生。Occurs when the ToolTip closes.

ToolTipOpening

ToolTip 打开时发生。Occurs when the ToolTip opens.

适用于

另请参阅