【问题标题】:Disable touch event handling of an InkCanvas in UWP在 UWP 中禁用 InkCanvas 的触摸事件处理
【发布时间】:2016-08-03 12:38:08
【问题描述】:

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

目前我已经尝试禁用操作事件,捕获它们,设置handled = false。到目前为止,我找不到正确的解决方案。有什么想法吗?

【问题讨论】:

  • “我找不到正确的解决方案” - 知道您的解决方案具体出了什么问题会有所帮助。

标签: c# touch uwp inkcanvas


【解决方案1】:

您可以在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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    相关资源
    最近更新 更多