View Issue Details

IDProjectCategoryView StatusLast Update
0001222NoesisGUIUnitypublic2019-04-30 06:20
Reporternokola Assigned Tosfernandez  
PriorityhighSeverityblock 
Status closedResolutionfixed 
Product Version2.1.0b17 
Target Version2.2.0Fixed in Version2.2.0b6 
Summary0001222: VisualTreeHelper.HitTest returns element with IsHitTestVisible == false
Description

The issue is that Noesis returns a "hit test success" for an element with IsHitTestVisible == false:

Steps To Reproduce
  1. Setup XAML like this:
    _mainContent (Grid)
    ViewBox
    ...
    UserControl IsHitTestVisible == false
    <-- mysterious border that doesn't exist in xaml -->
    Canvas IsHitTestVisible == false

  2. Call with some point inside the canvas
    HitTestResult result = VisualTreeHelper.HitTest(_mainContent, new Point(x, y));
    DependencyObject visualHit = result.VisualHit;
    FrameworkElement fe = visualHit as FrameworkElement;
    bool isHitTestVisible = fe.IsHitTestVisible;
    Debug.Log(isHitTestVisible);

Expected:
no hit test on canvas
Actual: hit test on mysterious border that is not in XAML and has IsHitTestVisible == false (see screenshot.)

PlatformAny

Activities

sfernandez

sfernandez

2018-01-20 11:24

manager   ~0005032

Last edited: 2018-01-20 11:24

A couple of questions:

  • Is the Canvas the direct logical child of the UserControl? I mean: UserControl.Content = Canvas?

  • Does the UserControl have its Background = Transparent? Because UserControl default template looks as follows:

<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>

By default UserControl has a null Background, so its template Border shouldn't return in a hit test.

Apart from that our default templates have a default Background = Transparent in the following controls: Label, RadioButton, CheckBox, ScrollViewer, ListBoxItem, MenuItem, ComboBoxItem, TreeViewItem, StatusBarItem, and ListViewItem. But these are required to properly click them with the mouse.

If you can attach a minimal project where this can be reproduced we can debug it and find what is occurring.

Thanks for your collaboration.

nokola

nokola

2018-01-20 16:47

reporter   ~0005035

Thanks! yes - it was a background=transparent causing the hit test to occur. Removing it canceled hit testing as well. Note that the behavior where hit testing is being ignored looks like a WPF bug: https://social.msdn.microsoft.com/Forum ... ?forum=wpf
I propose to deviate from WPF on this one since it's obviously an issue if hit testing returns elements with IsHitTestVisible == false. It's great that you value compatibility so much. In this case, perhaps it's a good idea to fix the bug and have a list of "Fixed in Noesis" differences somewhere compared to WPF. What do you think?

nokola

nokola

2018-01-20 16:47

reporter   ~0005036

And yes, the Canvas is a direct logical child of the UserControl

nokola

nokola

2018-01-20 16:48

reporter   ~0005037

For completeness:
<UserControl x:Class="FantasiaPhone.UnityImageFrame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Transparent" IsHitTestVisible="False">
<Canvas x:Name="frameRoot" IsHitTestVisible="False">

nokola

nokola

2018-01-27 02:31

reporter   ~0005054

ai_enabled has good suggestion in the forums: add a HitTest overload with boolean flag to allow IsHitTestVisible = false to work. http://www.noesisengine.com/forums/viewtopic.php?f=3&t=1170&start=90#p7473

In addition, can be mentioned somewhere in docs as "beneficial deviation from WPF behavior".
What do you think?

sfernandez

sfernandez

2018-01-29 14:48

manager   ~0005058

We decided to implement in C# the callback version of the HitTest function.
This will work for any situation and makes code compatible with WPF.

nokola

nokola

2018-01-29 18:28

reporter   ~0005062

Thanks, sounds good! hopefully not too taxing on the system due to pinvoke-s (can't really tell without profiling)

ai_enabled

ai_enabled

2018-06-02 08:59

updater   ~0005213

Please give higher priority to the implementation of the C# HitTest method with the callback delegate for the next update.
Without it, we have to rely on a very problematic and complex workaround code.

nokola

nokola

2018-06-02 18:28

reporter   ~0005214

Note: having a callback, while good idea, may have significant performance implications if we have to switch from managed to native code.
In addition (or instead of) to callback, can we have a boolean parameter e.g. "emulateWpfBehavior" that is true by default and mimics the WPF bug, and false otherwise?

(to be fair, I think the WPF behavior is just a bug, ideally Noesis fixes it in your implementation and you work better than WPF on this one. There's no reason why an IsHitTestVisible==false should ever hit)

ai_enabled

ai_enabled

2018-06-02 18:38

updater   ~0005215

Yes, having a parameter or simply another method will be good enough for our needs. When it was discussed on the forums, I've also supported this much more efficient approach.

ai_enabled

ai_enabled

2018-12-28 13:25

updater   ~0005379

Any updates on this?

We decided to implement in C# the callback version of the HitTest function. This will work for any situation and makes code compatible with WPF.

sfernandez

sfernandez

2018-12-31 11:21

manager   ~0005380

Haven't work on this yet but is something we are going to address before releasing the final 2.2 version.

nokola

nokola

2019-04-30 06:20

reporter   ~0005653

Thanks for the fix!

Issue History

Date Modified Username Field Change
2018-01-20 04:46 nokola New Issue
2018-01-20 04:46 nokola File Added: NoesisHitTestFail.jpg
2018-01-20 11:24 sfernandez Assigned To => sfernandez
2018-01-20 11:24 sfernandez Status new => feedback
2018-01-20 11:24 sfernandez Note Added: 0005032
2018-01-20 11:24 sfernandez Note Edited: 0005032
2018-01-20 16:47 nokola Note Added: 0005035
2018-01-20 16:47 nokola Status feedback => assigned
2018-01-20 16:47 nokola Note Added: 0005036
2018-01-20 16:48 nokola Note Added: 0005037
2018-01-27 02:31 nokola Note Added: 0005054
2018-01-29 14:48 sfernandez Note Added: 0005058
2018-01-29 18:28 nokola Note Added: 0005062
2018-06-02 08:59 ai_enabled Note Added: 0005213
2018-06-02 18:28 nokola Note Added: 0005214
2018-06-02 18:38 ai_enabled Note Added: 0005215
2018-11-01 02:14 jsantos View Status public => private
2018-11-22 12:00 sfernandez Target Version => 2.2.0
2018-11-22 12:00 sfernandez View Status private => public
2018-11-22 12:00 sfernandez Platform => Any
2018-12-28 13:25 ai_enabled Note Added: 0005379
2018-12-31 11:21 sfernandez Note Added: 0005380
2019-01-16 13:15 sfernandez Status assigned => resolved
2019-01-16 13:15 sfernandez Resolution open => fixed
2019-01-16 13:15 sfernandez Fixed in Version => 2.2.0b6
2019-04-30 06:20 nokola Status resolved => closed
2019-04-30 06:20 nokola Note Added: 0005653
2019-04-30 18:19 sfernandez File Deleted: NoesisHitTestFail.jpg
2025-10-10 13:29 jsantos Category Unity3D => Unity