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

前端 未结 3 1667
感动是毒
感动是毒 2021-01-30 02:00

I\'m trying to show a tooltip regardless of a buttons state, but this does not seem to do the trick:

相关标签:
3条回答
  • 2021-01-30 02:26

    ToolTipService.ShowOnDisabled="True"

    0 讨论(0)
  • 2021-01-30 02:34

    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 loose any other styles that have been applied to checkbox or button before. If you dont use any other styles for button or checkbox you can remove the BasedOn=.. parts

    0 讨论(0)
  • 2021-01-30 02:39

    This is a good method to add to your startup code

    ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
        typeof(FrameworkElement),
        new FrameworkPropertyMetadata(true));
    
    0 讨论(0)
提交回复
热议问题