title: UWP Is it Possible To Override Hit Testing?
body: <p>I'm coming to UWP from years writing WPF UIs.</p>
  
  <p>With a WPF control it is possible to provide custom hit testing logic by overriding the control's HitTestCore method as follows:</p>
  
  <pre><code>protected override HitTestResult HitTestCore(PointHitTestParameters params)
  {
      //Do some kind of test on params.HitPoint
      if (HitPointIsOverTheControl(params.HitPoint))
          return new PointHitTestResult(this, params.HitPoint);
      else
          return null;
  }
  </code></pre>
  
  <p>I have been using this approach successfully to allow me to test if the mouse is over any irregular shaped PNG image (in an image control) by testing the image pixel that is directly beneath the current mouse point to see if it has an alpha channel byte value of 0, and if so return null in the above function.</p>
  
  <p>In other words this approach allows me to pick through the PNG alpha channel mask to whatever might be below it in the visible stack of controls. And it works amazingly well.</p>
  
  <p>Now to UWP...</p>
  
  <p>I cannot find a similar approach to the above in the UWP framework so I suspect 'hit test overriding' is not available in UWP.</p>
  
  <p>Can anyone tell me if this approach is still possible in UWP and if not, is there an alternative approach I can use to achieve the same result?</p>
  
  <p>Thanks</p>
  
  <p>Edit: Example</p>
  
  <p>Let's assume there are 2 image controls on top of each other,  the topmost control is an image of a yellow circle with a hole in the middle and the bottom image is a solid blue square which is completely covered by the top control but can be partly seen through the hole in the circle.</p>
  
  <p>Now I want to be able to a) move the circle by clicking on it's yellow part or b) move the blue square from underneath by clicking on it through the hole in the circle.</p>
  
  <p>OK. When I move the mouse over the yellow circle, it fires PointerMoved events and I can then decide if the mouse is over part of the PNG image mask.  So far so good.</p>
  
  <p>Now let's say the mouse is over the hole in the middle of the circle, I really want to start receiving all Pointer and Manipulation events from the square and not the circle.  The only way I can think of doing this is to set the property 'IsHitTestVisible=false' on the circle whenever the mouse is over the 'hole' part of the image and set 'IsHitTestVisible=true' on the circle whenever the mouse is over the 'yellow' part of the image.</p>
  
  <p>The problem with this approach is that as soon as I set 'IsHitTestVisible=false' on the circle then it will no longer raise further PointerMoved events.</p>
  
  <p>In other words, it's too late to start altering IsHitTestVisible properties in PointerMoved events, hence why being able to override HitTestCore in WPF was so useful, as this occurs prior to Pointer events being raised.</p>
  
  <p>So now I know that HitTestCore overriding is not available in UWP (which is a real shame to be honest), is there any other way to achieve what I am describing?  For example can I forward pointer events and touch events onto a second control when they are raised by a first control, and in doing so also have the events ignored by the first control?</p>
  
  <p>Any ideas welcome</p>