Uwp 指针加压vs轻敲

Uwp 指针加压vs轻敲,uwp,windows-10-universal,c++-cx,Uwp,Windows 10 Universal,C++ Cx,在我的Win10应用程序中,用户可以用Surface笔点击屏幕,并将形状放置在图像画布上。这工作得很好,但有时应用程序会调用两次PointerPressed,导致添加两个形状。 我试着把代码移到一个点击回调。但是,使用TappedRoutedEventArgs^时,限制被攻破,我不知道如何获得与PointerRoutedEventArgs^相同的信息 我现在使用 onPenTouched(Platform::Object^ sender, Windows::UI::Xaml::Input::Po

在我的Win10应用程序中,用户可以用Surface笔点击屏幕,并将形状放置在图像画布上。这工作得很好,但有时应用程序会调用两次
PointerPressed
,导致添加两个形状。 我试着把代码移到一个点击回调。但是,使用
TappedRoutedEventArgs^
时,限制被攻破,我不知道如何获得与
PointerRoutedEventArgs^
相同的信息 我现在使用

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

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

   if (p->Properties->IsEraser){
        //do stuff
   }
}
确定正在使用笔的哪一端。
如何从
tappedroutedventargs
获取此信息

我尝试了中建议的解决方案,建议使用bool标志来防止双重调用,但这不起作用

更新 使用中建议的解决方法可以实现能够获得
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
属性来检测是否正在使用擦除。希望它是一个可靠且稳定的值。

当我们点击控件时,将触发
PointerPressed
事件,并且
Tapped
事件将在
PointerPressed
事件之后触发。当我们快速点击控件两次时,点击事件将触发一次。当我们第二次点击控件时,只有按下的
指针将被触发。这是故意的

如果要在
点击
事件中获取
,我们可以使用
tappedroutedventargs.GetPosition
方法获取点

如果要在
点击
事件中获取
PointErroredEventArgs
,作为一种解决方法,我们可以在代码中定义
TappedRoutedEventArgs
属性。我们可以在
PointerPressed
事件中将
tappedroutedventargs
PointerPressed
设置为它。我们可以在
Tap
事件中获取
tappedroutedventargs

例如:

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),因此我可以使用它来检测正在使用的笔的哪一端,但它感觉不太可靠。