Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wpf

People also ask

Can we show tooltip on disabled button?

By default, tooltips will not be displayed on disabled elements. However, you can enable this behavior by using the following steps: Add a disabled element like the button element into a div whose display style is set to inline-block . Set the pointer event as none for the disabled element (button) through CSS.

How do I disable WPF tooltip?

You will need to set ToolTipService. ShowOnDisabled to True on the Button in order to have the Tooltip visible at all when the Button is disabled. You can bind ToolTipService. IsEnabled on the Button to enable and disable the Tooltip.

What is tooltip in XAML?

The ToolTip element in XAML adds a tooltip to a WPF control. The ToolTip class represents a tooltip in C#. The ToolTip property of a control represents the tool tip of the control. Code examples in this this article show how to attach Tooltips to WPF controls using C# and XAML.


ToolTipService.ShowOnDisabled="True"


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.


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.