tags:

views:

36

answers:

2

The simplified example this; picture a Venn diagram made from two elements, A and B, that overlap. If I mouse over (A AND (NOT B)) all of A lights up. If I mouse over (B AND (NOT A)) all of B lights up. If I mouse over (A AND B), BOTH should light up. Only the top most is marked as having the mouse over it.

Is there a way to allow IsMouseOver to tunnel like this? If not, any suggestions?

+1  A: 

Use IsMouseDirectlyOver property. It seems to be thing you need.

http://msdn.microsoft.com/en-us/library/system.windows.uielement.ismousedirectlyoverproperty.aspx

STO
Actually, that's not it. IsMouseDirectlyOver is false if there is any occlusion from a child element. For IsMouseOver, child elements don't count, just the parent's boundary. IsMouseDirectlyOver is MORE specific. Since there is no child relationship between my Venn circles, I want to be LESS specific about what's directly over.
Ball
+1  A: 

You can do manual hit testing using VisualTreeHelper. This can go into a MouseMove handler on some parent object. Here I'm assuming a Venn diagram made of ellipses named RedCircle and BlueCircle:

bool overRed = false;
bool overBlue = false;
if (BlueCircle.IsMouseOver || RedCircle.IsMouseOver)
{
    HitTestParameters parameters = new PointHitTestParameters(e.GetPosition(RedCircle));
    VisualTreeHelper.HitTest(RedCircle, new HitTestFilterCallback(element => HitTestFilterBehavior.Continue), result =>
    {
        if (result.VisualHit == RedCircle)
            overRed = true;
        return HitTestResultBehavior.Continue;
    }, parameters);

    parameters = new PointHitTestParameters(e.GetPosition(BlueCircle));
    VisualTreeHelper.HitTest(BlueCircle, new HitTestFilterCallback(element => HitTestFilterBehavior.Continue), result =>
    {
        if (result.VisualHit == BlueCircle)
            overBlue = true;
        return HitTestResultBehavior.Continue;
    }, parameters);
}
John Bowen
The missing piece is WHEN to hit test. This will vary from situation to situation. In addition, you need to hit test from a joint parent of the overlapping objects. While that's no problem in my toy example, in my real situation I had to traverse towards the root in the logical tree for the common parent. Thanks!
Ball