Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ToolTip binding to work with a ComboBox?

Tags:

c#

wpf

tooltip

xaml

Currently I have a ComboBox defined as:

<ComboBox Name="comboItems" ItemsSource="{Binding Path=EnumDataItems}"
            DisplayMemberPath="Description" 
            ToolTip="{Binding Path=ToolTip}" // never displays the value
            SelectedValuePath="Value" SelectedValue="{Binding Path=Value}" />

Everything works except the ToolTip. The property that it should bind to; ToolTip does contain a value. I'm sure of this because when I do the following, I see a result confirming that ToolTip contains a value:

<ComboBox Name="comboItems" ItemsSource="{Binding Path=EnumDataItems}" 
            DisplayMemberPath="ToolTip" // I replaced 'Description' with 'ToolTip'
            ToolTip="{Binding Path=ToolTip}"
            SelectedValuePath="Value" SelectedValue="{Binding Path=Value}"/>

Having replaced Description with ToolTip I can see that the value of ToolTip is appearing on the screen. However

ToolTip="{Binding Path=ToolTip}"

still doesn't work. If I attempt to display ToolTip as follows:

ToolTip="ToolTip" 

it just displays the word 'ToolTip'.

How can I get ToolTip to display a value?

like image 652
binncheol Avatar asked Jun 29 '12 09:06

binncheol


2 Answers

If a ToolTip for every ComboBoxItem is what you want you can do this:

<ComboBox.ItemContainerStyle>
    <Style>
        <Setter Property="Control.ToolTip" Value="{Binding ToolTip}" />
    </Style>
</ComboBox.ItemContainerStyle>
like image 120
LPL Avatar answered Nov 14 '22 22:11

LPL


ToolTip="{Binding Path=ToolTip}" binds to ToolTip property of current combo box DataContext (object that contains EnumDataItems property). Assuming you want to set ToolTip of ComboBox to currently selected item's ToolTip property value, this should fix the problem:

ToolTip="{Binding Path=SelectedItem.ToolTip, RelativeSource={RelativeSource Self}}"
like image 36
max Avatar answered Nov 14 '22 21:11

max