工具提示可见性上的绑定错误
Binding error On ToolTip visibility
我正在尝试将工具提示的可见性 属性 绑定到按钮的 IsEnabled
<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>
但我收到以下错误:
"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')"
我也试过了
<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>
但后来我得到
"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') "
ToolTip 与其 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>
我正在尝试将工具提示的可见性 属性 绑定到按钮的 IsEnabled
<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>
但我收到以下错误:
"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')"
我也试过了
<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>
但后来我得到
"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') "
ToolTip 与其 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>