IT박스

wpf : 명령으로 버튼을 비활성화 할 때 툴팁을 표시하는 방법은 무엇입니까?

itboxs 2020. 6. 15. 21:59
반응형

wpf : 명령으로 버튼을 비활성화 할 때 툴팁을 표시하는 방법은 무엇입니까?


버튼 상태에 관계없이 툴팁을 표시하려고하지만 트릭을 수행하지 않는 것 같습니다.

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

명령으로 인해 버튼이 비활성화되어있을 때 툴팁을 표시하려면 어떻게해야합니까? CanExecute return false?

노트 :

ToolTipService.ShowOnDisabled = "true"는 매력처럼 작동합니다. 내 예제에서 이것이 작동하지 않는 이유는 버튼과 관련된 스타일이 컨트롤 템플릿을 재정의하고 버튼이 비활성화되어있을 때 버튼에서 적중 테스트를 해제했기 때문입니다 (IsHitTestVisible = false). 컨트롤 템플릿에서 적중 테스트를 다시 활성화하면 버튼이 비활성화되었을 때 툴팁이 나타납니다.


ToolTipService.ShowOnDisabled = "True"


이것은 시작 코드에 추가하는 좋은 방법입니다

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

비활성화 된 모든 버튼 및 확인란에 툴팁을 표시합니다.

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

참고 URL : https://stackoverflow.com/questions/4153539/wpf-how-to-show-tooltip-when-button-disabled-by-command

반응형