我想让鼠标悬停在TextBlock上时出现文本气泡。
以下代码是我能得到的最接近的代码,但它只是将文本注入 TextBox.Text 本身并更改颜色。我希望在鼠标悬停期间在原始文本块上方有一个例如 Border/StackPanel/TextBlock浮动在不同的图层上。
如何使用首字母缩略词标签制作类似于 Web 体验的悬停面板?
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.";
}
}
}