Search code examples
c#silverlightxamlbindingtooltip

Hide tooltip if binding is null


Currently i've got the following code to show a tooltip.

<Border BorderBrush="Black"
        BorderThickness="{Binding Border}"
        Height="23"
        Background="{Binding Color}">
<ToolTipService.ToolTip>
    <TextBlock Text="{Binding TooltipInformation}" />
</ToolTipService.ToolTip>

This is presented in a ItemsControl with about 25 items. Only a few of these have a value set to TooltipInformation

If TooltipInforation is an empty string, it still shows the tooltipbox containing the textblock as a very small window (about 5px high and 20px wide). Even if I set the textblock visbility to collapsed.

Is there a way to completely remove the tooltip if the value of TooltipInformation is null or a empty string?


Solution

  • One way you can do that is wrap the ToolTip in a Rectangle and give it a Transparent color. Then you just set the Visibility to Collapsed on this Rectangle.

    Update:

    <Border Background="#FFE45F5F">
        <Grid>
            <TextBlock Text="{Binding Property1}"/>
            <Rectangle Fill="Transparent" Visibility="{Binding Property2, Converter={StaticResource BooleanToVisibilityConverter}}" ToolTipService.ToolTip="{Binding TooltipInformation}"/>
        </Grid>
    </Border>