PointerPressed 与 Tapped
PointerPressed vs Tapped
在我的 Win10 应用程序中,用户可以使用 Surface 触控笔点击屏幕并在图像上放置形状 canvas。这工作得很好,但是有一个错误,有时应用程序调用 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
获取此信息?
我已经尝试了 中建议的解决方案,该解决方案建议使用 bool 标志来防止重复调用,但这不起作用。
更新
使用 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
属性 来检测是否正在使用擦除。希望它是一个可靠和稳定的价值。
当我们点击控件时,PointerPressed
事件将被触发,Tapped
事件将在 PointerPressed
事件之后被触发。当我们快速点击 Control 两次时,Tap 事件将被触发一次。当我们第二次点击 Control 时,只有 PointerPressed
会被触发。这是设计使然。
如果你想在Tapped
事件中获得Point
,我们可以使用TappedRoutedEventArgs.GetPosition
方法获得积分。
如果您想在 Tap
事件中获得 PointerRoutedEventArgs
,作为解决方法,我们可以在您的代码中定义一个 TappedRoutedEventArgs
属性。我们可以在PointerPressed
事件中将PointerPressed
的TappedRoutedEventArgs
设置为它。我们可以在 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;
}
在我的 Win10 应用程序中,用户可以使用 Surface 触控笔点击屏幕并在图像上放置形状 canvas。这工作得很好,但是有一个错误,有时应用程序调用 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
获取此信息?
我已经尝试了
更新
使用 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
属性 来检测是否正在使用擦除。希望它是一个可靠和稳定的价值。
当我们点击控件时,PointerPressed
事件将被触发,Tapped
事件将在 PointerPressed
事件之后被触发。当我们快速点击 Control 两次时,Tap 事件将被触发一次。当我们第二次点击 Control 时,只有 PointerPressed
会被触发。这是设计使然。
如果你想在Tapped
事件中获得Point
,我们可以使用TappedRoutedEventArgs.GetPosition
方法获得积分。
如果您想在 Tap
事件中获得 PointerRoutedEventArgs
,作为解决方法,我们可以在您的代码中定义一个 TappedRoutedEventArgs
属性。我们可以在PointerPressed
事件中将PointerPressed
的TappedRoutedEventArgs
设置为它。我们可以在 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;
}