programing

wpf: 명령에 의해 버튼이 비활성화되었을 때 툴팁을 표시하는 방법

newnotes 2023. 4. 10. 22:15
반응형

wpf: 명령에 의해 버튼이 비활성화되었을 때 툴팁을 표시하는 방법

버튼 상태에 관계없이 툴팁을 표시하려고 하는데 이 방법으로는 효과가 없는 것 같습니다.

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

명령으로 인해 버튼이 비활성화되었을 때 툴팁을 표시하려면 어떻게 해야 합니까?false 반환을 실행할 수 있습니까?

주의:

ToolTipService.Show On Disabled="true"는 매우 효과적입니다.이 예에서는 버튼과 관련된 스타일이 컨트롤 템플릿을 재정의하고 버튼이 비활성화되면 버튼의 히트 트립이 꺼지기 때문입니다(IsHitTestVisible=false).컨트롤 템플릿에서 히트 테스트를 다시 활성화하면 버튼이 비활성화되었을 때 툴팁이 표시됩니다.

xaml 요소에서 직접 사용할 수 있습니다.

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

기동 코드에 추가하는 방법은 다음과 같습니다.

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

이를 통해 에서 상속되는 모든 클래스에 대해FrameworkElement컨트롤 인스턴스가 비활성화되어 있는 경우에도 툴팁이 표시됩니다.여기에는 툴팁이 포함될 수 있는 모든 요소가 포함됩니다.

비활성화된 모든 버튼 및 확인란에 대한 도구 설명 표시:

<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>

BasedOn=...이전에 확인란이나 버튼에 적용된 다른 스타일이 손실되는 것을 방지합니다.단추 또는 체크박스에 다른 스타일을 사용하지 않으면BasedOn=..부품.

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

반응형