views:

383

answers:

1

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>
+1  A: 

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>
TabbyCool
Thank you for your answer. It works fine...
Vi
Cool, glad to help. Can you accept the answer for me please? Thanks :-)
TabbyCool