Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force showing a tooltip in WPF

Tags:

c#

wpf

tooltip

I'd like to show a tooltip when I move the mouse. Here is my code:

 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;
        }

However, the tooltip disappears after I click on the grid.

Is there a way to force showing the tooltip?

like image 204
user316030 Avatar asked Apr 17 '10 03:04

user316030


1 Answers

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

or

var tt = SomeElement.ToolTip as ToolTip;
if (tt != null) tt.IsOpen = true;
like image 103
tmt Avatar answered Oct 01 '22 03:10

tmt