InkCanvas 操作事件

InkCanvas manipulation event

当 InkPresenter 的唯一 InputDeviceType 是 CoreInputDeviceTypes::Pen 时,InkCanvas 会发出 ManipulationDelta 事件。当我将 InputDeviceType 更改为更多类型时,则不会。这是为什么?

InkCanvas->InkPresenter->InputDeviceTypes = CoreInputDeviceTypes::Mouse | CoreInputDeviceTypes::Touch | CoreInputDeviceTypes::Pen;

InkCanvas->ManipulationMode = ManipulationModes::Scale | ManipulationModes::TranslateX | ManipulationModes::TranslateY;
InkCanvas->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &ClassName::OnManipulationDeltaEvent); // OnManipulationDeltaEvent does not get called

基于 InkCanvas 的 Remark 部分,它提到:

The configuration of the InkPresenter determines the pointer event handling behavior of the InkCanvas. You must set InkPresenter.InputDeviceTypes to CoreInputDeviceTypes.None for the InkCanvas to process pointer events, otherwise they are passed to the InkPresenter object.

所以如果你将InputDeviceTypes设置为Pen,当你使用鼠标划动时,InkCanvas可以处理指针事件。但是如果将 InputDeviceTypes 设置为 Mouse 并使用 mouse 设置为 Stroke,InkCanvas 将无法处理指针事件,它将传递给 InkPresenter 对象。如果你想捕捉鼠标移动的事件,你可以订阅StrokeContinued事件。

.h:

void MyStrokeContinued(Windows::UI::Input::Inking::InkStrokeInput^ sender, Windows::UI::Core::PointerEventArgs^ e);

.cpp:

MainPage::MainPage()
{
    InitializeComponent();

    InkCanvas->InkPresenter->InputDeviceTypes = CoreInputDeviceTypes::Mouse| CoreInputDeviceTypes::Pen;
    InkCanvas->InkPresenter->StrokeInput->StrokeContinued += ref new Windows::Foundation::TypedEventHandler< InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &MainPage::MyStrokeContinued);
}

void MainPage::MyStrokeContinued(InkStrokeInput^ sender, Windows::UI::Core::PointerEventArgs^ e) {
    //do somthing
}