0

I am working on a project that involves the WPF InkCanvas control. I chose to use WPF over UWP due to its ability to synchronously save and load ink strokes.

However, I cannot seem to prevent touch input from drawing on the canvas.

I have posted code below:

    private void MainCanvas_TouchDown(object sender, TouchEventArgs e)
    {
        initialX = e.GetTouchPoint(null).Position.X;
        initialY = e.GetTouchPoint(null).Position.Y;
        e.Handled=true;
    }

    private void MainCanvas_TouchMove(object sender, TouchEventArgs e)
    {
        currentX = e.GetTouchPoint(null).Position.X;
        currentY = e.GetTouchPoint(null).Position.Y;
        e.Handled = true;
    }

    private void MainCanvas_TouchUp(object sender, TouchEventArgs e)
    {
        finalX = e.GetTouchPoint(null).Position.X;
        finalY = e.GetTouchPoint(null).Position.Y;

        double deltaX = finalX - currentX;
        if (deltaX < -_swipeDeltaX)
        {
            notebook.SwitchToNextPage();
            Render();
        }
        else if (deltaX > -_swipeDeltaX)
        {
            notebook.SwitchToPreviousPage();
            Render();
        }
        else { 
        
        }
        e.Handled =(true);

    }
Michael Sohnen
  • 953
  • 7
  • 15

1 Answers1

-1

You could stop the event from doing something with e.Handled = true; on the stylus event.

AZ Software
  • 108
  • 8
  • Sorry, I would like to clarify my question. I want to allow inking with stylus input and disallow inking with touch. The second link you provided asks the same question as me, but no one provided a working answer. You can mark my question as duplicate. – Michael Sohnen May 25 '22 at 18:42
  • You would set `e.Handled = true;` in order to cancel further handling of an event by a control. Besides that, it would be interesting to see a working example where touch drawing is completely disabled by doing this on the involved events. – Clemens May 25 '22 at 18:56