ToolTipService 類別

定義

表示提供靜態方法來顯示 工具提示的服務。

public ref class ToolTipService sealed
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ToolTipService final
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ToolTipService
Public NotInheritable Class ToolTipService
繼承
Object Platform::Object IInspectable ToolTipService
屬性

範例

下列程式代碼範例示範 工具提示的位置模式。

<StackPanel Margin="120" >
    <TextBlock Text="ToolTip Control"/>
    <TextBlock Text="Hover over an item to see its ToolTip: " Margin="0,10"/>
    <ListBox Width="100" HorizontalAlignment="Left">
        <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>

備註

ToolTip 必須指派給其擁有者的另一個 UI 元素。 在 Extensible Application Markup Language (XAML) 中,使用 ToolTipService.ToolTip 附加屬性將 ToolTip 指派給擁有者。 在程式代碼中,使用 ToolTipService.SetToolTip 方法將 ToolTip 指派給擁有者。

放置

根據預設, 工具提示 會顯示在指標上方置中。 位置不受應用程式視窗限制,因此 工具提示 可能會部分或完全顯示在應用程式視窗界限之外。

如果 工具提示 遮蔽它所參考的內容,您可以調整其位置。 使用 ToolTipService.Placement 附加屬性,將 工具提示 放在指標的上方、下方、左或右。

如果沒有明確的 PlacementTarget,工具提示的位置目標就是元素,指定其 TooltipService.ToolTip 附加屬性值的值。 任何 Placement 值 (附加屬性或明確 ToolTip 元素上的屬性) 套用至該目標。

XAML 附加屬性

ToolTipService 是數個 XAML 附加屬性的主機服務類別。

為了支援 XAML 處理器對附加屬性的存取,以及公開對等 的 getset 作業給程式代碼,每個 XAML 附加屬性都有一對 Get 和 Set 存取子方法。 在程序代碼中取得或設定值的另一種方式是使用相依性屬性系統,呼叫 GetValueSetValue 並將識別符字段傳遞為相依性屬性識別碼。

附加屬性 Description
放置 取得或設定值,這個值表示工具提示相對於放置目標的位置。
PlacementTarget 取得或設定相對於工具提示位置的物件。
ToolTip 取得或設定專案工具提示的物件或字串內容。

屬性

PlacementProperty

識別 ToolTipService.Placement XAML 附加屬性。

PlacementTargetProperty

識別 ToolTipService.PlacementTarget XAML 附加屬性。

ToolTipProperty

識別 ToolTipService.Tooltip XAML 附加屬性。

附加屬性

Placement

取得或設定值,這個值表示工具提示相對於放置目標的位置。

PlacementTarget

取得或設定相對於工具提示位置的物件。

ToolTip

取得或設定專案工具提示的物件或字串內容。

方法

GetPlacement(DependencyObject)

取得指定之目標專案的 ToolTipService.Placement XAML 附加屬性值。

GetPlacementTarget(DependencyObject)

取得指定之目標專案的 ToolTipService.PlacementTarget XAML 附加屬性值。

GetToolTip(DependencyObject)

取得物件的 ToolTipService.ToolTip XAML 附加屬性的值。

SetPlacement(DependencyObject, PlacementMode)

設定指定之目標專案的 ToolTipService.Placement XAML 附加屬性值。

SetPlacementTarget(DependencyObject, UIElement)

設定指定之目標專案的 ToolTipService.PlacementTarget XAML 附加屬性值。

SetToolTip(DependencyObject, Object)

設定 ToolTipService.ToolTip XAML 附加屬性的值。

適用於

另請參閱