Silverlight Quick Tip: How to Perform a Hit Test

Tuesday, August 11, 2009

In some cases, especially when developing rich UI application developer need to identify which control were clicked or under mouse pointer at some point of time or just under some coordinate at the UI. For those purposes Silverlight provides “FindElementsInHostCoordinates” function in VisualTreeHelper class. The function gets the Point (coordinate on the screen) or Rect (rectangular area) and UIElement which will be checked recursively to have any visual child's in desired coordinate/area. The function returns IEnumerable<UIElement>. In most cases, especially when using custom controls the returned list will have many UIElements. They need to be filtered out....