Another option is to use your own converter. I prefer this method, for example, for a TextBlock tooltip that displays TextBlock text, but for the case there is no text, an empty tooltip is not needed.
XAML Code:
//step #1 xmlns:local="clr-namespace:MyNamespace" //step #2 - into Window.Resources or other <local:StringToVisibleTooltip x:Key="StringToVis" /> //step #3 - example of use <TextBlock ...other attributes... TextTrimming="CharacterEllipsis"> <TextBlock.ToolTip> <ToolTip Visibility="{Binding Path=Text, Converter={StaticResource StringToVis}}"> <TextBlock Text="{Binding Text}"/> </ToolTip> </TextBlock.ToolTip> </TextBlock>
And the code for
namespace MyNamespace { public class StringToVisibleTooltip : IValueConverter { public StringToVisibleTooltip() { } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null && ((string)value).Length > 0)
source share