語言

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 元素。 在可擴充應用程式標記語言(XAML)中,使用 ToolTipService.ToolTip 附加屬性將 工具提示 指派給擁有者。 在程式碼中,使用 ToolTipService.SetToolTip 方法將 工具提示 指派給擁有者。

放置

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

如果提示( ToolTip )遮蔽了它所指的內容,你可以調整它的位置。 使用 ToolTipService.Placement attached 屬性,將 工具提示 置於指標的上方、下方、左側或右側。

若沒有明確的 PlacementTarget,則工具提示的放置目標就是指定其 TooltipService.ToolTip 附加屬性值值的元素。 任何 Placement 值(無論是附加屬性或明確工具提示元素上的屬性)都適用於該目標。

XAML 附加屬性

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

為了支援 XAML 處理器對附加屬性的存取,並向程式碼暴露等效的 get 與 set 操作,每個 XAML 附加屬性都有一對 Get 與 Set 存取器方法。 另一種在程式碼中取得或設定值的方法是使用相依屬性系統,呼叫 GetValue 或 SetValue ,並將識別欄位傳入相依屬性識別碼。

附屬財產 Description
放置 取得或設定一個值,表示工具提示與放置目標的位置關係。
定位目標 取得或設定工具提示所定位物件的相對值。
工具提示 取得或設定元素工具提示的物件或字串內容。

屬性

名稱 Description
PlacementProperty

識別 ToolTipService.Placement XAML 附加屬性。

PlacementTargetProperty

識別 ToolTipService.PlacementTarget XAML attached 屬性。

ToolTipProperty

識別 ToolTipService.Tooltip XAML 附加屬性。

附加屬性

名稱 Description
Placement

取得或設定一個值,表示工具提示與放置目標的位置關係。

PlacementTarget

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

ToolTip

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

方法

名稱 Description
GetPlacement(DependencyObject)

取得指定目標元素的 ToolTipService.Placement XAML 附加屬性值。

GetPlacementTarget(DependencyObject)

取得指定目標元素的 ToolTipService.PlacementTarget XAML 附加屬性值。

GetToolTip(DependencyObject)

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

SetPlacement(DependencyObject, PlacementMode)

為指定目標元素設定 ToolTipService.Placement XAML 附加屬性值。

SetPlacementTarget(DependencyObject, UIElement)

為指定目標元素設定 ToolTipService.PlacementTarget XAML attached 屬性值。

SetToolTip(DependencyObject, Object)

設定 ToolTipService.ToolTip XAML attached 屬性的值。

適用於

另請參閱