Event Handlers not working with inkCanvas in Windows Universal App

余生长醉 提交于 2019-12-09 23:49:10

问题


I am not able to make PointerPressed, PointerReleased (any pointer event) work.

I have written this line of code to support touch

inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch;

from the solutions that I found online, I have tried this

inkCanvas.PointerReleased += inkCanvas_PointerReleased;

and this

inkCanvas.AddHandler(PointerReleasedEvent, new PointerEventHandler(inkCanvas_PointerReleased), true);

and simply through XAML as well:

     <InkCanvas x:Name="inkCanvas" 
PointerPressed="inkCanvas_PointerPressed" 
PointerMoved="inkCanvas_PointerMoved" PointerReleased="inkCanvas_PointerReleased" 
Tapped="inkCanvas_Tapped">

I am testing the app in my device (not on emulator). what is it that I am missing?


回答1:


There are few things to consider. First When you declare InkCanvas you need to Let the UIElement know what input type it can expect. There are 3 commonly used types.

CoreInputDeviceTypes.Mouse ( Desktop / Notebooks without touch capability )
CoreInputDeviceTypes.Pen ( Surfacebooks and other pen enabled devices )
CoreInputDeviceTypes.Touch ( all other devices that accept Touch )

So you need to make sure these are declared on your InkCanvas.

Once done, see if your pointerevents are fired when called from XAML. If it still does not work, Try below.

CoreInkIndependentInputSource  core = CoreInkIndependentInputSource.Create(inkCanvas.InkPresenter);
core.PointerPressing += Core_PointerPressing;
core.PointerReleasing += Core_PointerReleasing;
core.PointerMoving += Core_PointerMoving;

Edit 2: Below are the methods for all 3 actions

        private void Core_PointerMoving(CoreInkIndependentInputSource sender, PointerEventArgs args)
        {
            throw new NotImplementedException();
        }

        private void Core_PointerReleasing(CoreInkIndependentInputSource sender, PointerEventArgs args)
        {
            throw new NotImplementedException();
        }

        private void Core_PointerPressing(CoreInkIndependentInputSource sender, PointerEventArgs args)
        {
            throw new NotImplementedException();
        }

Hope this helps.



来源:https://stackoverflow.com/questions/38467349/event-handlers-not-working-with-inkcanvas-in-windows-universal-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!