Show WPF tooltip on disabled item only
- by DT
Just wondering if it is possible to show a WPF on a disabled item ONLY (and not when the item is enabled).
I would like to give the user a tooltip explaining why an item is currently disabled.
I have an IValueConverter to invert the boolean IsEnabled property binding. But it doesn't seem to work in this situation. The tooltip is show both when the item is enabled and disabled.
So is is possible to bind a tooltip.IsEnabled property exclusively to an item's own !IsEnabled?
Pretty straightforward question I guess, but code example here anyway:
public class BoolToOppositeBoolConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (targetType != typeof(bool))
throw new InvalidOperationException("The target must be a boolean");
return !(bool)value;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (targetType != typeof(bool))
throw new InvalidOperationException("The target must be a boolean");
return !(bool)value;
}
#endregion
}
And the binding:
<TabItem Header="Tab 2" Name="tabItem2" ToolTip="Not enabled in this situation." ToolTipService.ShowOnDisabled="True" ToolTipService.IsEnabled="{Binding Path=IsEnabled, ElementName=tabItem2, Converter={StaticResource oppositeConverter}}">
<Label Content="Item content goes here" />
</TabItem>
Thanks folks.