Sinatr
Sinatr

Reputation: 21999

ComboBox tooltip is not displayed

I am trying following code:

<ComboBox x:Name="comboBox">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Content="{Binding}" ToolTip="This will never be shown, why?" />
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

Then I assign some ItemSource in code behind, select item and trying to mouseover combobox. The result - no tooltip.

If I do same with ListBox - tooltip is shown for each item. If I open ComboBox popup - tooltip is shown for each item.

If I snoop it:

Then there is no CheckBox in visual tree. But content presenter displays it. What is going on?

Of course I can additionally bind ComboBox.Tooltip to e.g. its SelectedValue or SelectedIndex.ToolTip, but it will not work always and depends on content and ComboBox configuration: is it collection of ComboBoxItems or maybe ItemsSource, is it using ValuePath or not, etc.

I want to understand why there is not CheckBox. And I want tooltip from datatemplate to be shown.


It might be a bug of Snoop or something else, but after opening and closing ComboBox popup and hitting refresh button in Snoop it finally shows CheckBox:

But then my question still: Why tooltip is not shown? I can see it is there, but mouseovering ComboBox doesn't display anything.

Upvotes: 0

Views: 369

Answers (1)

mm8
mm8

Reputation: 169270

Why tooltip is not shown?

Since an element can only appear once in the element tree, the ComboBox creates a visual copy of the CheckBox using a VisualBrush and then displays the clone in the selection box: https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/ComboBox.cs,896

And the Rectangle that hosts the VisualBrush has no Tooltip.

Upvotes: 1

Related Questions