当鼠标光标悬停在 WPF 中的按钮上时,如何显示工具提示

How do I make a tooltip displayw hen mouse cursor is over button in WPF

如何在 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";
}