1

This is my code. Path drawing on the mouse, but it not drawing on touch for the first time and then draw the path. A path is not drawn on the first touch.

Xaml

<Grid PointerMoved="Grid_PointerMoved"
      PointerPressed="Grid_PointerPressed">

    <InkCanvas x:Name="inkCanvas" ManipulationMode="System" />

</Grid>

C#

// InputDevice type as None

      private void InkPresenter_StrokesCollected(Windows.UI.Input.Inking.InkPresenter sender, 
        Windows.UI.Input.Inking.InkStrokesCollectedEventArgs args)
    {
        inkCanvas.InkPresenter.InputDeviceTypes = 
             Windows.UI.Core.CoreInputDeviceTypes.None;

    }


    private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
        inkCanvas.InkPresenter.InputDeviceTypes = 
                 Windows.UI.Core.CoreInputDeviceTypes.Mouse |
                        Windows.UI.Core.CoreInputDeviceTypes.Touch;
    }


   private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        inkCanvas.InkPresenter.InputDeviceTypes = 
         Windows.UI.Core.CoreInputDeviceTypes.Mouse |
            Windows.UI.Core.CoreInputDeviceTypes.Touch;
    }
Santhiya
  • 191
  • 2
  • 14

1 Answers1

0

The reason is that you are resetting the InputDeviceTypes to None after the drawing is complete, so on first touch the InkPresenter is instructed not to draw.

I see no reason to change the InputDeviceTypes when they are reactivated each time you press on the InkCanvas anyway. So you can just set the InputDeviceTypes to Mouse and Touch in the constructor and just remove all three event handlers.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • Thanks.. But this is my requirement. I want to disable the drawing on stroke collected and enable on pointer moved. Is there any other way? – Santhiya Feb 09 '18 at 10:26
  • Oh, It seems I don't understand the requirement... Could you please describe what is the behavior difference between what you want and my suggestion? – Martin Zikmund Feb 09 '18 at 10:29
  • I want to get the fingers count, if the finger count is 2 enable the zooming, otherwise disable the zooming(this is my actual requirement). I can't take the finger count on InkCanvas because of the InkPresenter. So I tried the CustomDrying , but it did not help because it returns the StrokeContainer value is null, so am not able to do Undo and Redo. So I tried this way, it is working on the mouse. The problem only with touch. I need finger count in InkCanvas and also I want stroke container. – Santhiya Feb 09 '18 at 10:46
  • I have written an answer on custom drying here in this answer https://stackoverflow.com/questions/48436425/how-to-remove-the-inkstroke-when-using-the-activecustomdrying-in-uwp/48438729#48438729 , maybe it might help. But I will try to think about a solution for this in the meantime. – Martin Zikmund Feb 09 '18 at 11:03
  • Thanks for your solution. It is useful to detect the fingers count, but I am confused how to do Undo and Redo operations. I dropped the custom drying because of the Undo and Redo operations. – Santhiya Feb 09 '18 at 11:10
  • Any idea about this. – Santhiya Feb 19 '18 at 05:57