wpf: how to show tooltip when button disabled by command?

This is a good method to add to your startup code:

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

It ensures that for any class inheriting from FrameworkElement, tooltips are shown even if a control instance is disabled. This covers all elements that can have a tooltip.


You can use on xaml element directly:

<Grid ToolTipService.ShowOnDisabled="True" ... >

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.

Tags:

Wpf