2010-11-11 65 views
105

我試圖顯示工具提示,無論按鈕狀態,但這似乎並沒有這樣的伎倆:wpf:如何通過命令禁用按鈕時顯示工具提示?

<Button Command="{Binding Path=CommandExecuteAction}" 
     ToolTip="{Binding Path=Description}" ToolTipService.ShowOnDisabled="true" 
     Style="{StaticResource toolbarButton}"> 
    <Image Source="{Binding Path=Icon}"></Image> 
</Button> 

我如何能顯示工具提示當按鈕被禁用由於command.CanExecute返回假?

注:

ToolTipService.ShowOnDisabled = 「真」 的作品就像一個魅力。這在我的例子中不起作用的原因是因爲與按鈕相關的樣式重新定義了控件模板,並且在按鈕被禁用時關閉了按鈕的命中測試(IsHitTestVisible = false)。在控制模板中重新啓用命中測試時,會在按鈕被禁用時顯示工具提示。

+0

可能重複http://stackoverflow.com/questions/3149016/wpf-tooltip-visibility) – 2010-11-11 10:45:28

+0

我正在使用ToolTipService.ShowOnDisabled,但它不起作用。 – Marius 2010-11-11 11:10:43

+1

只需刪除此問題。我做了一個小測試項目,ToolTipService.ShowOnDisabled工作得很好。 – Marius 2010-11-11 11:33:54

回答

214

ToolTipService.ShowOnDisabled = 「真」

+8

MSDN參考:http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltipservice.aspx – David 2013-03-08 05:27:49

10

這是添加到您的啓動代碼的好方法

ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
    typeof(Control), 
    new FrameworkPropertyMetadata(true)); 
[WPF工具提示可見性(的
相關問題