无论按钮状态如何,我都试图显示工具提示,但这似乎没有办法:
<Button Command="{Binding Path=CommandExecuteAction}"
ToolTip="{Binding Path=Description}" ToolTipService.ShowOnDisabled="true"
Style="{StaticResource toolbarButton}">
<Image Source="{Binding Path=Icon}"></Image>
</Button>
Run Code Online (Sandbox Code Playgroud)
如果由于command.CanExecute返回false而禁用按钮时如何显示工具提示?
注意:
ToolTipService.ShowOnDisabled ="true"就像一个魅力.这在我的示例中不起作用的原因是因为与按钮关联的样式重新定义了控件模板,并在禁用按钮时关闭按钮上的命中测试(IsHitTestVisible = false).重新启用controltemplate中的命中测试,使按钮被禁用时显示工具提示.
Kis*_*mar 282
ToolTipService.ShowOnDisabled = "真"
sac*_*cha 22
这是添加到启动代码的好方法
ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
typeof(Control),
new FrameworkPropertyMetadata(true));
Run Code Online (Sandbox Code Playgroud)
使工具提示对所有禁用的按钮和复选框可见:
<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>
Run Code Online (Sandbox Code Playgroud)
这BasedOn=...可以防止您丢失之前应用于复选框或按钮的任何其他样式。如果您不使用任何其他样式的按钮或复选框,您可以删除这些BasedOn=..部分。