我想讓文字泡泡在鼠標超過時出現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.";
}
}
}