View Issue Details

IDProjectCategoryView StatusLast Update
0000699NoesisGUIC++ SDKpublic2019-04-18 16:49
Reporterthemirrortruth Assigned Tosfernandez  
PrioritynormalSeverityminor 
Status resolvedResolutionopen 
Fixed in Version2.2.0 
Summary0000699: C++ API VisualTreeHelper.HitTest()
Description

http://www.noesisengine.com/forums/viewtopic.php?f=3&t=761

And whether it is possible to implement this method in C#?

PlatformAny

Activities

sfernandez

sfernandez

2015-08-03 16:26

manager   ~0002815

Last edited: 2015-08-03 16:27

We will implement the following version of the HitTest function in a future release:

https://msdn.microsoft.com/en-us/library/ms608753(v=vs.110).aspx

Meanwhile, if you are interested, I can show you a tricky (and inefficient) way to simulate that behavior using the available HitTest(visual, point) function.

themirrortruth

themirrortruth

2015-08-03 16:35

reporter   ~0002816

Yes, I would like to know about it. Big thanks.

sfernandez

sfernandez

2015-08-03 18:07

manager   ~0002818

Last edited: 2015-08-03 18:08

Here you are:


public enum HitTestResultBehavior
{
// Continue hit testing against the next visual in the visual tree hierarchy.
Continue,
// Stop any further hit testing and return from the callback.
Stop
}

public delegate HitTestResultBehavior HitTestResultCallback(HitTestResult result);

public static class VisualTreeHelperExtension
{
public static void HitTest(Visual reference, Point point,
HitTestResultCallback resultCallback)
{
List<KeyValuePair<UIElement, bool>> visible =
new List<KeyValuePair<UIElement,bool>>();

    HitTestResult hit;
    Visual lastHit = null;
    do
    {
        hit = VisualTreeHelper.HitTest(reference, point);

        if (hit.visualHit != null &&
            resultCallback(hit) == HitTestResultBehavior.Continue)
        {
            lastHit = hit.visualHit;

            // Make this child invisible for HitTest, so other elements can be hit
            UIElement e = lastHit as UIElement;
            if (e != null)
            {
                visible.Add(new KeyValuePair<UIElement, bool>(e, e.IsHitTestVisible));
                e.IsHitTestVisible = false;
            }
        }
        else
        {
            lastHit = null;
        }
    }
    while (lastHit != null);

    // restore IsHitTestVisible
    foreach (var item in visible)
    {
        item.Key.IsHitTestVisible = item.Value;
    }
}

}

nokola

nokola

2018-12-10 19:22

reporter   ~0005362

+1 for this fix. We do all kinds of workarounds to keep code efficient and working as expected (hardcoded naming for grids, using custom bounds to determine hit test, tagging elements in XAML.)

Issue History

Date Modified Username Field Change
2015-08-03 14:56 themirrortruth New Issue
2015-08-03 16:26 sfernandez Note Added: 0002815
2015-08-03 16:26 sfernandez Assigned To => sfernandez
2015-08-03 16:26 sfernandez Status new => feedback
2015-08-03 16:27 sfernandez Note Edited: 0002815
2015-08-03 16:35 themirrortruth Note Added: 0002816
2015-08-03 16:35 themirrortruth Status feedback => assigned
2015-08-03 18:07 sfernandez Note Added: 0002818
2015-08-03 18:07 sfernandez Status assigned => feedback
2015-08-03 18:07 sfernandez Note Edited: 0002818
2015-08-03 18:08 sfernandez Note Edited: 0002818
2015-08-03 18:08 sfernandez Note Edited: 0002818
2018-11-01 02:14 jsantos View Status public => private
2018-11-21 13:58 jsantos View Status private => public
2018-11-21 13:58 jsantos Platform => Any
2018-12-10 19:22 nokola Note Added: 0005362
2019-04-18 16:49 sfernandez Status feedback => resolved
2019-04-18 16:49 sfernandez Fixed in Version => 2.2.0