wpf:当按钮被命令禁用时如何显示工具提示? [英] wpf: how to show tooltip when button disabled by command?
问题描述
无论按钮状态如何,我都试图显示工具提示,但这似乎不起作用:
I'm trying to show a tooltip regardless of a buttons state, but this does not seem to do the trick:
<Button Command="{Binding Path=CommandExecuteAction}"
ToolTip="{Binding Path=Description}" ToolTipService.ShowOnDisabled="true"
Style="{StaticResource toolbarButton}">
<Image Source="{Binding Path=Icon}"></Image>
</Button>
当按钮因 command.CanExecute 返回 false 而被禁用时,如何显示工具提示?
How can i show the tooltip when the button is disabled due to command.CanExecute returning false?
注意:
ToolTipService.ShowOnDisabled="true" 就像一个魅力.这在我的示例中不起作用的原因是,与按钮关联的样式重新定义了控件模板,并在禁用按钮时关闭了按钮上的命中测试 (IsHitTestVisible=false).在控制模板中重新启用命中测试会使工具提示在按钮被禁用时出现.
ToolTipService.ShowOnDisabled="true" works like a charm. The reason this didn't work in my example is because the style associated with the button redefines the controltemplate and turned off hit-testing on the button when the button was disabled (IsHitTestVisible=false). Re-enabling hit-testing in the controltemplate made the tooltip appear when the button was disabled.
推荐答案
ToolTipService.ShowOnDisabled="True"
ToolTipService.ShowOnDisabled="True"
这篇关于wpf:当按钮被命令禁用时如何显示工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!