David David - 1 year ago 105
C# Question

WPF & XAML: DisplayToolTipPath

ListBox control has property

that specifies what is showed inside ListBoxItem(s).

Unfortunately, I miss property
. Do you know some simple way how to simulate this situation in XAML (I preffer XAML solution to code).

My attempt is something like this:

<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="ToolTip" Value="{Binding ??? {Binding ToolTipMemberPath}}" />

Answer Source


<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="ToolTip" Value="{Binding Path=DataContext.ToolTipMemberPath, RelativeSource={RelativeSource Self}}" />

With ToolTipMemberPath the desired prop on your ListBoxItem Class.


The easiest solution when TooltipMemberPath is a parent property would involve a Converter:

<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="ToolTip">
            <MultiBinding Converter="{StaticResource PathToTooltipConverter}">
                <Binding RelativeSource="{RelativeSource Self}"/>
                <Binding Path="TooltipMemberPath" 
                         RelativeSource="{RelativeSource AncestorType={x:Type CustomListBoxControl:CustomListBox}}"/>


public class PathToTooltipConverter : IMultiValueConverter
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        ListBoxItem item = values[0] as ListBoxItem;
        string tooltipMemberPath = values[1] as string;

        if (tooltipMemberPath == null)
            return null;

        MyListBoxItemClass itemClass = (MyListBoxItemClass)item.DataContext;
        return itemClass.GetType().GetProperty(tooltipMemberPath).GetValue(itemClass, null);

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        throw new NotImplementedException();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download