【发布时间】:2015-09-10 19:42:36
【问题描述】:
如何在 WPF 中将鼠标悬停在按钮上时显示工具提示?
【问题讨论】:
-
使用样式来做到这一点like this
-
是的,一个工具提示。抱歉,我不知道英文这个词。
如何在 WPF 中将鼠标悬停在按钮上时显示工具提示?
【问题讨论】:
试试这个:
<Button ToolTipService.InitialShowDelay="5000"
ToolTipService.ShowDuration="2000"
ToolTipService.BetweenShowDelay="10000"
ToolTip="This is a tool tip." />
【讨论】:
“ToolTip”是需要设置的属性,以便将文本添加到正在主动悬停的控件。
【讨论】:
您可以创建 2 个事件:PointerEntered 和 PointerExited,为按钮绘制内容并为内容(或其模板)命名
Xaml:
<Button PointerEntered="Button_PointerEntered" PointerExited="Button_PointerExited" >
<Button.Content>
<TextBlock x:Name="txtBlock1" Text="not hovering" />
</Button.Content>
</Button>
在你处理这些事件的代码上:
private void Button_PointerEntered(object sender, PointerRoutedEventArgs e)
{
txtBlock1.Text = "hovering";
}
private void Button_PointerExited(object sender, PointerRoutedEventArgs e)
{
txtBlock1.Text = "not hovering";
}
【讨论】: