【发布时间】: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