【问题标题】:How do I make a tooltip displayw hen mouse cursor is over button in WPF当鼠标光标悬停在 WPF 中的按钮上时,如何显示工具提示
【发布时间】:2015-09-10 19:42:36
【问题描述】:

如何在 WPF 中将鼠标悬停在按钮上时显示工具提示?

【问题讨论】:

标签: c# wpf button mouse


【解决方案1】:

试试这个:

 <Button ToolTipService.InitialShowDelay="5000" 
    ToolTipService.ShowDuration="2000" 
    ToolTipService.BetweenShowDelay="10000" 
    ToolTip="This is a tool tip." />

【讨论】:

    【解决方案2】:

    “ToolTip”是需要设置的属性,以便将文本添加到正在主动悬停的控件。

    【讨论】:

      【解决方案3】:

      您可以创建 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";
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多