2016-08-03 96 views
0

我的应用程序正面有一个InkCanvas。 我希望它只与Stylus/Pen事件交互。所有其他事件应传递到画布下的各种控件。 我的意图是用笔检测InkCanvas上的手势,而其他操作事件由InkCanvas下面的控件处理(如触摸和惯性操作)。在UWP中禁用InkCanvas的触摸事件处理

目前我已经尝试禁用操纵事件,捕获它们,设置处理= false。到目前为止,我找不到合适的解决方案。有任何想法吗?

+0

*“我无法找到正确的解决方案“* - 这有助于了解您的解决方案具体出了什么问题。 – IInspectable

回答

0

可以在InkCanvasPointer事件检测输入模式(PointerDeviceType),例如:

<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"/> 

后面的代码:

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; 
    } 
}