无论按钮状态如何,我都试图显示工具提示,但这似乎不起作用:
<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 而被禁用时,如何显示工具提示?
注意:
ToolTipService.ShowOnDisabled="true"就像一个魅力。这在我的示例中不起作用的原因是,与按钮关联的样式重新定义了控件模板,并在禁用按钮时关闭了按钮上的 HitTest (IsHitTestVisible=false)。在控件模板中重新启用 HitTest 会在禁用按钮时显示工具提示。
最佳答案
您可以直接在xaml元素上使用:
<Grid ToolTipService.ShowOnDisabled="True" ... >
关于wpf:当按钮被命令禁用时如何显示工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4153539/