c# – 如何在WPF中强制显示工具提示

我想在移动鼠标时显示工具提示.
这是我的代码:

 private void Grid_MouseMove(object sender, MouseEventArgs e)
        {
            Grid grid = (Grid) sender;
            if (e.GetPosition(grid).X < 100)
                grid.ToolTip = e.GetPosition(grid).X.ToString();
            else
                grid.ToolTip = null;
        }

但是,单击网格后工具提示消失.

有没有办法强制显示工具提示?

最佳答案
var oldTT = SomeElement.ToolTip as ToolTip;
if (oldTT != null) oldTT.IsOpen = false;
SomeElement.ToolTip = new ToolTip
{
     Content = "Lalalalala",
    IsOpen = true,
};

要么

var tt = SomeElement.ToolTip as ToolTip;
if (tt != null) tt.IsOpen = true;

转载注明原文:c# – 如何在WPF中强制显示工具提示 - 代码日志