I have an InkCanvas and a touch screen on a specific touch display. This display is able to capture stylus events. Sadly it also captures touch events. On some occassions this is completly ok. But when an InkCanvas is shown, it should ONLY capture the stylus events and not the touch or the mouse events. Following normal Microsoft logic I used the following approach:
private void InkCanvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
TabletDeviceType? stylus = e.StylusDevice?.TabletDevice?.Type;
if (stylus == null || stylus != TabletDeviceType.Stylus)
e.Handled = true;
}
private void InkCanvas_PreviewTouchDown(object sender, TouchEventArgs e)
{
e.Handled = true;
}
private void InkCanvas_PreviewStylusDown(object sender, StylusDownEventArgs e)
{
TabletDeviceType? type = e.StylusDevice?.TabletDevice?.Type;
if (type == null || type == TabletDeviceType.Touch)
e.Handled = true;
}
Now the mouse is ignored and the stylus can draw freely on the InkCanvas. BUT even when I "cancelled" the PreviewTouchDown, the line is drawn. Ok, after releasing the touch, it is NOT applied to the StrokesCollection and it gets deleted from the InkCanvas, but it was there. For all to see. When I do the same with the mouse, the complete event is ignored, not only rolled back after MouseUp.
When I googled some time around there were a mass of solutions for the UWP-InkCanvas (mostly it would work out all by itself, because it, by standard, only allows stylus events). But I have to use .Net-Framework 4.8, so I cannot use Islands or the .net core ones.
I would even consider using a complete different user control. Does someone know of a solution or workaround?