Q:

Tooltip Visibility

I have the following code:
<DataTemplate>
    <!--<sdk:DataGridTextColumn Binding="{Binding Description}" Header="Description" Width="205" />-->
    <TextBlock  Text="{Binding Description}"    Width="232">
        <ToolTipService.ToolTip  >   
            <ToolTip Visibility="{Binding    }">
                <sdk:DataGrid AutoGenerateColumns="False" GridLinesVisibility="None" HeadersVisibility="None" Height="Auto" ItemsSource="{Binding Contains}" >
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding Code}" Header="Code" CanUserSort="False" />
                        <sdk:DataGridTextColumn Binding="{Binding Description}" Header="Description" CanUserSort="False"/> 
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>            
            </ToolTip>
        </ToolTipService.ToolTip>
    </TextBlock>
</DataTemplate>

I would like my tooltip to show, only if there are at least one row in the ItemsSource="{Binding Contains}"
What do I have to write in the Visibility property? 
Something like 
<ToolTip Visibility="{Binding Contains.Length > 0}">

But I can't figure out what the syntax should be! Any ideas?

A:

You are going to have to use a custom converter on that binding.  Visibility property is not boolean, it is an enum.

A:

This is a job for an implementation of IValueConverter.  Having posted many such examples in the past I realised that a couple of more general implementations would work of most of the time, so I blogged them.
The IValueConverter you need is my StringToObjectConverter blogged here.  With the code for this converter in your project you can create an instance of it in a resource like this:-
<Grid x:Name="LayoutRoot">
    <Grid.Resources>
        <local:StringToObjectConverter x:Key="CountToVisibility">
            <ResourceDictionary>
                <Visibility x:Key="__Default__">Visible</Visibility>
                <Visibility x:Key="0">Collapsed</Visibility>
            </ResourceDictionary>
        </local:StringToObjectConverter>
    </Grid.Resources>

and then used when binding to visibility, in you case:-
 <ToolTip Visibility="{Binding Contains.Length, Converter={StaticResource CountToVisibility}}">

BTW, are you sure you want Length not Count?

