墨迹画布操作事件

InkCanvas manipulation event

本文关键字:操作 事件 布操作      更新时间:2023-10-16

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

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 的备注部分,它提到:

墨迹演示器的配置确定指针事件 处理 InkCanvas 的行为。您必须设置 InkPresenter.InputDeviceTypes to CoreInputDeviceTypes.None for the InkCanvas 处理指针事件,否则它们将传递给 墨迹演示器对象。

因此,如果将"输入设备类型"设置为"笔",则在使用鼠标进行描边时,InkCanvas 可以处理指针事件。但是,如果将 InputDeviceType 设置为"鼠标"并使用鼠标进行描边,则 InkCanvas 无法处理指针事件,它将被传递给 InkPresenter 对象。如果要捕获鼠标移动的事件,可以订阅 StrokeContinuing 事件。

.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
}