Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 578
Theun Arbeider Avatar asked May 06 '11 11:05

Theun Arbeider


Video Answer


1 Answers

One way to hide an empty tooltip for all controls is to create a style in a resource dictionary that is included in your App.xaml. This style sets the visibility to collapsed when the tooltip is an empty string or null:

<!-- Style to hide tool tips that have an empty content. --> <Style TargetType="ToolTip">     <Style.Triggers>         <Trigger Property="Content"                  Value="{x:Static sys:String.Empty}">             <Setter Property="Visibility"                     Value="Collapsed" />         </Trigger>         <Trigger Property="Content"                  Value="{x:Null}">             <Setter Property="Visibility"                     Value="Collapsed" />         </Trigger>     </Style.Triggers> </Style> 

Also include sys namespace (for String.Empty):

xmlns:sys="clr-namespace:System;assembly=mscorlib" 
like image 132
HeWillem Avatar answered Sep 18 '22 23:09

HeWillem