title: Geometry HitTest UIElement in WPF
body: <p>Is there anyway to hit test an uielement using Geometry in WPF? I tried <code>VisualTreeHelper</code>, but it doesn't work. <code>UIElement</code> could raise mouse down event if a the mouse click on it with a point.</p>
  
  <p>However, I would like to raise an event if a geometry intersect the an <code>UIElement</code>. How could I do so?</p>
  
  <pre><code>public class MyUI : UIElement
  {
      protected override void OnReder(DrawingContext dc)
      {
          dc.DrawRectangle(..., new Rect(12,12,120,120));
          ...
      }
  }
  
  MyUI ui = new MyUI();
  Grid grid = new Grid();
  grid.Children.Add(ui);
  
  EllipseGeometry eg = new EllipseGeometry(new Rect(24,24,40,40));
  
  VisualTreeHelper.HitTest(grid, null, HitTestResult, new GeometryHitTestParameters(eg));
  
  if (results.Count &gt; 0)
      MessageBox.Show("Hit Count = "+results.ToString());
  
  ...
  
  List&lt;DependencyObject&gt; results;
  
  public HitTestResultBehavior HitTestResult(HitTestResult result)
  {
      results.Add(result.VisualHit);
      return HitTestResultBehavior.Continue;
  }
  </code></pre>