gpt4 book ai didi

c# - 如何在 WPF 中的鼠标悬停时显示悬停信息气泡?

转载 作者:可可西里 更新时间:2023-11-01 03:12:22 27 4
gpt4 key购买 nike

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

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

如何使用 acronym tag 制作类似于 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.";
}

}
}

最佳答案

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

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

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

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

关于c# - 如何在 WPF 中的鼠标悬停时显示悬停信息气泡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1841800/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com