1

Say that we have two superposed rectangle r1 and r2 where r1.Zindex < r2.Zindex. r2.IsHitTestVisible must be true because r2 has a tooltip and r2 is visible only if the mouse is over r1.

With the default WPF hit testing, when the mouse is over those rectangles, r2 is blinking because:

  • when r2 is not visible, r1 is the topmost hit test visible element, so the mouse is over r1 which set r2 as visible.
  • when r2 is visible, r1 is no longer the topmost hit test visible element, so the mouse is not considered to be over it, which in return hide r2.

Here is a concrete example :

Canvas canvas = new Canvas();
canvas.Width = 500;
canvas.Height = 300;

Rectangle r1 = new Rectangle();
r1.Width = 200;
r1.Height = 100;
r1.Fill = new SolidColorBrush(Colors.Red);
Canvas.SetLeft(r1, 100);
Canvas.SetTop(r1, 100);
canvas.Children.Add(r1);

Rectangle r2 = new Rectangle();
r2.Width = 200;
r2.Height = 100;
r2.Fill = new SolidColorBrush(Colors.Blue);
Canvas.SetLeft(r2, 100);
Canvas.SetTop(r2, 100);
canvas.Children.Add(r2);

r1.IsHitTestVisible = true;
r2.IsHitTestVisible = true;
r2.ToolTip = "r2";
r2.Visibility = Visibility.Hidden;

r1.MouseEnter += (sender, e) => r2.Visibility = Visibility.Visible;
r1.MouseLeave += (sender, e) => r2.Visibility = Visibility.Hidden;

To avoid this blinking scenario and to be able to display r2's tooltip, I would like to modify the default HitTesting algorithm so that :

  • r2 remains hit test visible, but does not stop the HitTest research when encountered.
  • r1 keeps the same behaviour.
A. Jacquet
  • 51
  • 9
  • Replace `r1.MouseLeave += ...` by `r2.MouseLeave += ...` – Clemens Oct 19 '16 at 07:10
  • The above code is juste an example. In the real code I just can't know when this kind of configuration will occure, I can only identify `r2`-like objects. – A. Jacquet Oct 19 '16 at 09:11

0 Answers0