【问题标题】:PointerPressed vs TappedPointerPressed vs Taped
【发布时间】:2017-10-22 00:20:50
【问题描述】:

在我的 Win10 应用程序中,用户可以使用 Surface Pen 在屏幕上点击并将形状放置在图像画布上。这很好用,但是有一个错误,有时应用程序调用PointerPressed 两次 - 导致添加了两个形状。 我尝试将代码移至 Tapped 回调。但是限制是 Tapped 使用TappedRoutedEventArgs^,我无法弄清楚如何获得与PointerRoutedEventArgs^ 相同的信息。
我使用的是当前使用...

onPenTouched(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e){

   PointerPoint^ p = e->GetCurrentPoint(imgCanvas);

   if (p->Properties->IsEraser){
        //do stuff
   }
}

确定正在使用笔的哪一端。
我如何从TappedRoutedEventArgs 获取这些信息?

我尝试了this almost-duplicate question 中建议的解决方案,该解决方案建议使用布尔标志来防止双重调用,但这不起作用。

更新 使用来自Jayden Gu 的建议解决方法可以实现能够获得PointerPoint^ 的目标,但属性与预期不符。像这样调试输出...

OutputDebugString(p->Properties->IsEraser.ToString()->Data());
OutputDebugString(p->Properties->IsInverted.ToString()->Data());
OutputDebugString(p->Properties->IsPrimary.ToString()->Data());

如下所示

Tapping with pen tip =  false false true  
Tapping with pen eraser = false true true  
Tapping with finger = false false true  

现在我必须使用IsInverted 属性来检测是否正在使用擦除。希望这将是一个可靠且稳定的值。

【问题讨论】:

    标签: uwp windows-10-universal c++-cx


    【解决方案1】:

    当我们点击控件时,PointerPressed 事件将被触发,Tapped 事件将在PointerPressed 事件之后触发。当我们快速点击 Control 两次时,Tap 事件将被触发一次。当我们第二次点击 Control 时,只会触发 PointerPressed。这是设计使然。

    如果你想在Tapped事件中获取Point,我们可以使用TappedRoutedEventArgs.GetPosition方法来获取要点。

    如果您想在Tap 事件中获取PointerRoutedEventArgs,作为一种解决方法,我们可以在您的代码中定义一个TappedRoutedEventArgs 属性。我们可以在PointerPressed事件中设置PointerPressedTappedRoutedEventArgs给它。我们可以在Tap 事件中获得TappedRoutedEventArgs

    例如:

    Windows::UI::Xaml::Input::PointerRoutedEventArgs^ nowPointerRoutedEventArgs;
    
    
    void App2::MainPage::Rectangle_Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
    {
        Windows::UI::Input::PointerPoint^ p = nowPointerRoutedEventArgs->GetCurrentPoint(imgCanvas);
    }
    
    void App2::MainPage::Rectangle_PointerPressed(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
    {
        nowPointerRoutedEventArgs = e;
    }
    

    【讨论】:

    • 谢谢,这几乎可以工作......但是,当使用橡皮擦敲击时,p->Properties->IsEraser 总是返回 false。 p->Properties->IsInverted 在使用橡皮擦时返回 true(笔尖为 false)所以我可以使用它来检测正在使用笔的哪一端,但感觉它不会那么健壮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多