0
votes

I am trying to bind the visibility property of the ToolTip to the IsEnabled of the Button

 <Button Name="bbb" Content="Train" Command="{Binding TrainCmd}" ToolTipService.ShowOnDisabled="True">
      <Button.ToolTip>
          <ToolTip Content="{Binding TrainToolTip}" Visibility="{Binding IsEnabled, Converter={StaticResource InverseBooleanToVisibilityConverter}, ElementName=aaa}">
          </ToolTip>
      </Button.ToolTip>
 </Button> 

but I get the following error:

"System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=aaa'. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'ToolTip' (Name=''); target property is 'Visibility' (type 'Visibility')"

I also tried

 <Button Content="Train" Command="{Binding TrainCmd}" ToolTipService.ShowOnDisabled="True">
    <Button.ToolTip>
        <ToolTip Content="{Binding TrainToolTip}" Visibility="{Binding IsEnabled, Converter={StaticResource InverseBooleanToVisibilityConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}}"/>
    </Button.ToolTip>
 </Button>

but then I get

"System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Button', AncestorLevel='1''. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'ToolTip' (Name=''); target property is 'Visibility' (type 'Visibility') "

1
post your viewmodel also. - Frebin Francis
Well, your button name is "bbb", but you want to bind to IsEnabled of "aaa", which can't be found. - Lennart
Why do you want to do ToolTipService.ShowOnDisabled="True" if you dont want to show tooltip? Why not just use <Button Content="Train" Command="{Binding TrainCmd}" ToolTip="Test"/> directly? - Carbine

1 Answers

2
votes

ToolTip does not reside in the same visual tree as it's PlacementTarget.

 <Button Name="bbb" Content="Train" Command="{Binding TrainCmd}" ToolTipService.ShowOnDisabled="True">
      <Button.ToolTip>
           <ToolTip Content="{Binding TrainToolTip}" Visibility="{Binding PlacementTarget.IsEnabled, Converter={StaticResource InverseBooleanToVisibilityConverter}, RelativeSource={RelativeSource Self}">
            </ToolTip>
       </Button.ToolTip>
 </Button>