Mathias Weyel
Mathias Weyel

Reputation: 819

WPF: Prevent tooltip from changing mouse enter/leave event behaviour of component

I have a WPF user control in which there are two custom controls.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="65" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <MyControl x:Name="leftControl" Grid.Column="0" />
    <MyControl x:Name="rightControl" Grid.Column="2" />
</Grid>

The custom controls react on mouse enter and mouse leave events for doing stuff. However, they also have tooltips. The left component does explicitly lie above the right component in order to allow for tooltips not being hidden by the right component in case they reach into the area of the right component.

My problem now: The tooltip seems to extend the bounds of the left component by its own. When a tooltip had been shown that covers part of the area of the right control and I hover over the right control, I get enter/leave events for both as if I had entered the left control as soon as entering the area where the tooltip had been before, while still hovering the right control.

How can I tell WPF to ignore the tooltip area when raising mouse enter or leave?

Some screenshots to illustrate:

  1. Hovering over the left component with a tooltip partly covering the area of the right component 1. Hovering over the left component with a tooltip partly covering the area of the right component:

  2. Hovering over the right component 2. Hovering over the right component

  3. Hovering over the right component at the point where the tooltip ends. Enter/Leave events have been raised. Mouse cursor added for illustration of mouse cursor position. 3. Hovering over the right component at the point where the tooltip ends. Enter/Leave events have been raised. Mouse cursor added for illustration of mouse cursor position

Thanks!

Upvotes: 0

Views: 688

Answers (1)

myermian
myermian

Reputation: 32505

There is an alternative to using the Tooltip: A tooltip or something similar move with cursor in wpf

Simply create a Popup that moves relative to your mouse. When you leave the control the Popup is hidden. This is a good alternative to your problem. You might want to make adjustments to where you show it (i.e. if it reaches the right edge it goes to the left of the mouse). I know it isn't a direct answer, but it's a solution. :)

Upvotes: 2

Related Questions