Trying to finding First Node from root
Posted: 02 Jul 2019, 07:25
I've been looking at re-arranging my elements in Noesis, when any button is clicked, that root object needs to come forward.
I looked into getting the VisualTreeHelper.GetRoot from HitResult.VisualHit but I couldn't cast it as a UIElement
so I decided to try getting the Root from a list of HitTestResults
following https://docs.microsoft.com/en-us/dotnet ... arameters_ as a reference
Currently, I have the following error with the newly implimented Hit Check
I looked into getting the VisualTreeHelper.GetRoot from HitResult.VisualHit but I couldn't cast it as a UIElement
so I decided to try getting the Root from a list of HitTestResults
following https://docs.microsoft.com/en-us/dotnet ... arameters_ as a reference
Code: Select all
private List<DependencyObject> hitResultsList = new List<DependencyObject>();
private void Listen4ChildClick()
{
UnityEngine.Vector3 mousePos = Input.mousePosition;
Point mousePoint = uiRoot.PointFromScreen(new Point(mousePos.x, Screen.height - mousePos.y));
VisualTreeHelper.HitTest(uiRoot, null, new HitTestResultCallback(MyHitTestResult), new PointHitTestParameters(mousePoint));
HitTestResult hit = VisualTreeHelper.HitTest(uiRoot, mousePoint);
if (hit.VisualHit != null)
{
UIElement Panel = VisualTreeHelper.GetRoot(hit.VisualHit) as UIElement;
if (ActiveWindows.ContainsValue((UIElement)Panel))
{
uiRoot.Children.Remove(Panel);
uiRoot.Children.Add(Panel);
}
}
}
private HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
hitResultsList.Add(result.VisualHit);
return HitTestResultBehavior.Continue;
}NullReferenceException: Object reference not set to an instance of an object
Noesis.VisualTreeHelper.OnHitTestFilter (System.Int32 callbacksId, System.IntPtr targetPtr) (at Assets/NoesisGUI/Plugins/API/Proxies/VisualTreeHelper.cs:57)
UnityEngine.Debug:LogException(Exception)
NoesisUnity:OnUnhandledException(Exception) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:142)
Noesis.Error:UnhandledException(Exception) (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:18)
Noesis.VisualTreeHelper:OnHitTestFilter(Int32, IntPtr) (at Assets/NoesisGUI/Plugins/API/Proxies/VisualTreeHelper.cs:61)
Noesis.VisualTreeHelper:VisualTreeHelper_HitTestCallback(HandleRef, Point&, Int32, Callback_HitTestFilter, Callback_HitTestResult)
Noesis.VisualTreeHelper:HitTestCallbackHelper(Visual, Point, Int32, Callback_HitTestFilter, Callback_HitTestResult) (at Assets/NoesisGUI/Plugins/API/Proxies/VisualTreeHelper.cs:83)
Noesis.VisualTreeHelper:HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters) (at Assets/NoesisGUI/Plugins/API/Proxies/VisualTreeHelper.cs:45)