【问题标题】:How can I make a hover info bubble appear on mouseover in WPF?如何使悬停信息气泡出现在 WPF 中的鼠标悬停上?
【发布时间】:2010-12-22 22:39:48
【问题描述】:

我想让文本气泡在鼠标悬停在TextBlock上时出现。

以下代码是我能得到的最接近的,但它只是将文本注入 TextBox.Text 本身并更改颜色。我想要一个例如在鼠标悬停期间,原始文本块上方的边框/StackPanel/TextBlock浮动在不同的图层上

如何使用acronym tag 制作类似于网络体验的悬停面板?

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace TestHover29282
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            TextBlock tb = new TextBlock();
            tb.Text = "test";

            tb.MouseEnter += new MouseEventHandler(tb_MouseEnter);
            tb.MouseLeave += new MouseEventHandler(tb_MouseLeave);

            MainStackPanel.Children.Add(tb); 
        }

        void tb_MouseLeave(object sender, MouseEventArgs e)
        {
            TextBlock tb = sender as TextBlock;
            tb.Background = new SolidColorBrush(Colors.Transparent);
            tb.Text = "test";
        }

        void tb_MouseEnter(object sender, MouseEventArgs e)
        {
            TextBlock tb = sender as TextBlock;
            tb.Background = new SolidColorBrush(Colors.Orange);
            tb.Text += " - this should be in a popup bubble.";
        }

    }
}

【问题讨论】:

    标签: c# wpf xaml hover mouseover


    【解决方案1】:

    您可以使用多种方法,一种是使用带有自定义样式的工具提示。 或者,您可以使用弹出控件,第三种选择是使用装饰器。

    我的直觉说你想要一个tooltip,但是。

    <TextBlock ToolTip="stuff, could even be a custom control, etc" Text="my text" />
    

    然后您可以使用ToolTipService 可附加属性为所述工具提示设置各种选项,从延迟到工具提示位置

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-26
        • 1970-01-01
        • 2022-11-11
        • 1970-01-01
        • 2011-08-04
        • 2018-09-03
        相关资源
        最近更新 更多