如何:创建工具提示

更新:2007 年 11 月

下面的示例演示如何为 TextBox 元素定义工具提示控件。

示例

下面的示例演示如何通过为 ToolTip 属性分配文本来定义工具提示。

<TextBox HorizontalAlignment="Left">TextBox with ToolTip
  <TextBox.ToolTip>
    <TextBlock>Useful information goes here.</TextBlock>
  </TextBox.ToolTip>
</TextBox>

下面的示例演示如何通过将 ToolTip 对象分配给 ToolTip 属性来定义工具提示。

<TextBox HorizontalAlignment="Left">ToolTip with non-text content
  <TextBox.ToolTip>
    <ToolTip>
      <DockPanel Width="50" Height="70">
        <Image Source="data\flower.jpg"/>
        <TextBlock>Useful information goes here.</TextBlock>
      </DockPanel>
    </ToolTip>
  </TextBox.ToolTip>
</TextBox>

下面的示例使用代码来生成 ToolTip 对象。此示例创建一个 ToolTip (tt) 并将它与 Button 关联。

button = New Button()
button.Content = "Hover over me."
tt = New ToolTip()
tt.Content = "Created with Visual Basic"
button.ToolTip = tt
cv2.Children.Add(button)
button = new Button();
button.Content = "Hover over me.";
tt = new ToolTip();
tt.Content = "Created with C#";
button.ToolTip = tt;
cv2.Children.Add(button);

请参见

任务

如何:在已禁用的控件上启用 ContextMenu

概念

ToolTip 概述

参考

ToolTip

ToolTipService

其他资源

ToolTip 帮助主题