0

I have an InkCanvas over the front of my application. I want it to only interact with Stylus/Pen events. All other events should be passed through to the various controls underneath the canvas. The intention is that I detect gestures on the InkCanvas with a pen, while other manipulation events are handled by the controls below the InkCanvas (such as touch and inertial manipulation).

Currently I've tried disabling manipulation events, capturing them, setting handled = false. So far I can't find the right solution. Any ideas?

JoshG
  • 775
  • 1
  • 7
  • 19

1 Answers1

-1

You can detect the input mode (PointerDeviceType) in the Pointer events of the InkCanvas, for example:

<ScrollViewer x:Name="scrollViewer" Width="400" Height="400" Background="LightBlue" VerticalAlignment="Center" HorizontalAlignment="Center"
              PointerPressed="scrollViewer_PointerPressed">
    <StackPanel>
        <Rectangle Height="300" Width="300" Fill="Red"/>
        <Rectangle Height="300" Width="300" Fill="Black"/>
    </StackPanel>
</ScrollViewer>
<InkCanvas x:Name="inkCanvas" Width="400" Height="400" GotFocus="inkCanvas_GotFocus" VerticalAlignment="Center" HorizontalAlignment="Center"
           Tapped="inkCanvas_Tapped" PointerPressed="inkCanvas_PointerPressed"/>

code behind:

private void inkCanvas_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    // Accept input only from a pen or mouse with the left button pressed.
    PointerDeviceType pointerDevType = e.Pointer.PointerDeviceType;
    if (pointerDevType == PointerDeviceType.Pen)
    {
        //TODO:
    }
    else
    {
        // Process touch or mouse input
        inkCanvas.Visibility = Visibility.Collapsed;
    }
}

private void scrollViewer_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    PointerDeviceType pointerDevType = e.Pointer.PointerDeviceType;
    if (pointerDevType == PointerDeviceType.Pen)
    {
        inkCanvas.Visibility = Visibility.Visible;
    }
    else
    {
        // Process touch or mouse input
        inkCanvas.Visibility = Visibility.Collapsed;
    }
}
Grace Feng
  • 16,564
  • 2
  • 22
  • 45