In my application, i have tried to implement the visibility of tooltip based on the dataGrid Column's text length by using a converter. I am facing some problems in displaying the toolTip text.
In the ToolTip, TextBlock's text binding is not working. If its binded with some hard coded strings, it works fine.
Here below is the code that i have added for the grid column...
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}">
<TextBlock.ToolTip>
<ToolTip
DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}"
Visibility="{Binding Converter={StaticResource ToolTipVis}}">
<TextBlock Text="{Binding Text}开发者_运维问答">
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
The DataContext of your ToolTip is set to System.Windows.Controls.TextBlock, since you have defined it as RelativeSource.Self.
If you lose the ToolTip DataContext, you should be able to bind to your Text property.
You might need to change your converter binding to reflect this though, but I'm not sure as I haven't tested this...
<ToolTip
Visibility="{Binding Path=PlacementTarget,
RelativeSource={x:Static RelativeSource.Self},
Converter={StaticResource ToolTipVis}}">>
<TextBlock Text="{Binding Path=Text}"/>
</ToolTip>
精彩评论