I'm coming to UWP from years writing WPF UIs.
With a WPF control it is possible to provide custom hit testing logic by overriding the control's HitTestCore method as follows:
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;
}
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.
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.
Now to UWP...
I cannot find a similar approach to the above in the UWP framework so I suspect 'hit test overriding' is not available in UWP.
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?
Thanks
Edit: Example
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.
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.
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.
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.
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.
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.
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?
Any ideas welcome