How to get a tooltip in WPF

I want 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 clicking on the grid.

Is there a way to get the tooltip to show?

+4
source share
2 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; 
+5
source

TooltipService.ShowDuration works, but you must set it on the object using a tooltip, for example:

  <Label ToolTipService.ShowDuration="120000" Name="lblTooltip" Content="Shows tooltip"> <Label.ToolTip> <ToolTip> <TextBlock>Hi world!</TextBlock> </ToolTip> </Label.ToolTip> 

+3
source

Source: https://habr.com/ru/post/1307208/


All Articles