Why doesn't VisualTreeHelper.FindElementsInHostCoordinates return any results?

Work on the Metro app in C #. I have a custom control that inherits from the Grid. MyGrid contains other user controls. I am trying to test for those controls in a PointerReleased handler:

void MyGrid_PointerReleased(object sender, PointerRoutedEventArgs e) { PointerPoint pt = e.GetCurrentPoint(this); var hits = VisualTreeHelper.FindElementsInHostCoordinates(pt.Position, this); int breakhere = hits.Count(); } 

After executing this code, hitCount is 0. If I move the PointerReleased handler, one control is higher in the hierarchical structure of the visual tree, then hitCount will be correct for the first time and 0 after that. I set up a test project with a similar XAML layout to try to reproduce the problem and it works correctly every time. So I'm not sure what I did that interferes with VisualTreeHelper. I am not sure how to continue debugging. Any ideas what might cause this function not to return results?

+4
source share

All Articles