ToolTipService 類別

定義

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

public ref class ToolTipService sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 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(Windows.Foundation.UniversalApiContract), 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
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

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

<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 附加屬性將 工具提示 指派給擁有者。 在程式碼中,使用 ToolTipService.SetToolTip 方法將 工具提示 指派給擁有者。

放置

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

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

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

舊版的注意事項

Windows 8.x工具提示 僅適用于 Windows。 工具提示類型可在Windows Phone專案中使用,以便與通用專案範本相容,但工具提示不會顯示在Windows Phone UI 中。

工具提示 只會顯示在應用程式視窗的界限內。 其位置可能會進行調整,以留在這些界限內。

XAML 附加屬性

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

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

附加屬性 描述
位置 取得或設定值,這個值表示 相對於 ToolTip 放置目標的位置。
PlacementTarget 取得或設定 相對於 所放置 的 物件 ToolTip
ToolTip 取得或設定專案的 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 附加屬性的值。

適用於

另請參閱