【问题标题】:how to show tooltip over disbabled button in uwp?如何在 uwp 中显示禁用按钮的工具提示?
【发布时间】:2020-07-11 22:46:27
【问题描述】:

如何在 UWP 中的禁用按钮上显示工具提示?

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

【问题讨论】:

  • 按钮被禁用...为什么要显示工具提示?
  • 即使它被禁用,我想在工具提示中显示按钮的用途?
  • Here is how to do the same thing in wpf。也许同样的解决方案也适用?
  • UWP 中不存在 ShowOnDisabled 属性

标签: c# uwp


【解决方案1】:

禁用按钮不仅会改变样式,还会拦截相关事件的触发。

例如,如果禁用,Button 将不会触发Pointer 相关事件。 Tooltip的显示条件是Pointer在控件上悬停一段时间。如果控件无法检测到Pointer 事件,则Tooltip 将永远不会遇到相应的触发器。

但如果你需要它显示,我们可以换一种方式:

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

我们可以把Tooltip放在不会被禁用的Grid上,这样可以避免这个问题。

谢谢。

【讨论】:

  • 它工作正常,但它增加了内存..还有其他方法吗??
  • 一个简单的Button无法实现你需要的功能(禁用后无法显示Tooltip)。如果觉得Grid很贵,可以换成其他控件,不过思路是一样的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-15
  • 2021-02-27
  • 2014-07-29
  • 1970-01-01
  • 2018-05-10
  • 1970-01-01
相关资源
最近更新 更多