我想让文字泡泡在鼠标超过时出现TextBlock。如何让鼠标悬停在WPF上出现悬停信息气泡?
以下代码是我能够得到的最接近的,但它只是将文本注入TextBox.Text本身并更改颜色。我想要一个例如在鼠标悬停期间浮动在不同层上的原始文本块上方的Border/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.";
}
}
}