2

how to show tooltip over disabled button in UWP?

Button b=new button();
b.IsEnabled=false;
b.content="Button";
ToolTip t= new ToolTip();
t.Content="Hello";
ToolTipService.SetToolTip(b, ToolTip);

1 Answers1

2

Disabling a button not only changes the style, but also intercepts the triggering of related events.

For example, if disabled, Button will not trigger Pointer related events. The display condition of the Tooltip is that the Pointer is hovering on the control for a period of time. If the control cannot detect the Pointer event, the Tooltip will never meet the corresponding trigger.

But if you need it to display, we can change it another way:

var grid = new Grid();
Button b = new Button();
b.IsEnabled = false;
b.Content = "Button";
ToolTip t = new ToolTip();
t.Content = "Hello";
grid.Children.Add(b);
ToolTipService.SetToolTip(grid, t);

We can put Tooltip on the Grid that will not be disabled, this can avoid this problem.

Thanks.

Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
  • its working fine,but it increase the memory..is there any other way ?? – PremKumar Shanmugam Apr 02 '20 at 08:10
  • A simple Button cannot achieve the functions you need (you cannot display Tooltip once it is disabled). If you think that the Grid is expensive, you can switch to other controls, but the idea is the same. – Richard Zhang Apr 02 '20 at 08:17
  • The proposed solution by wrapping the disabled Button in a Grid didn't work for me on WinUI 3. The tooltip text did not appear when hovering over with the mouse. I did manage to get it working though by setting . – SteffenSH Oct 01 '22 at 22:17