2016-08-03 95 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; 
    } 
}