180
votes

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>

How can i show the tooltip when the button is disabled due to command.CanExecute returning false?

Note:

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.

3
possible duplicate of WPF Tooltip VisibilityOJ.
I'm using the ToolTipService.ShowOnDisabled, but its not working.Marius
Just delete this question. I did a small test project and ToolTipService.ShowOnDisabled works just fine.Marius
I'm glad this question didn't get deleted. It quickly and accurately answered a question/problem I had, which is the exact reason I come to SO in the first place. Thanks for being Lazy(tm) Marius. :-)Jere.Jones
Excuse me, is there a way I can show it only when disabled?advapi

3 Answers

329
votes

ToolTipService.ShowOnDisabled="True"

33
votes

This is a good method to add to your startup code

ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
    typeof(FrameworkElement),
    new FrameworkPropertyMetadata(true));
4
votes

Make tooltip visible for ALL disabled Buttons and Checkboxes:

<Window.Resources>
    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}>
        <Setter Property="ToolTipService.ShowOnDisabled" Value="true"/>
    </Style>
    <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}>
        <Setter Property="ToolTipService.ShowOnDisabled" Value="true"/>
    </Style>
</Window.Resources>

The BasedOn=... prevents that you lose any other styles that have been applied to checkbox or button before. If you don't use any other styles for button or checkbox you can remove the BasedOn=.. parts.