Main Site Documentation

CP7 - Touch Wpf


#1

I’m trying to use the following code to detect a touch event:


_imgButton = new Image(_normalButton);
 _imgButton.TouchDown += imgButton_TouchDown;
     

But the TouchDown event never fires, what am I doing wrong?

I’m using a Cobra II & CP7 display.

BTW, this event fires:
display.ScreenPressed += display_ScreenPressed;


#2

This sounds like the same issue in using the CP7 with Glide. It is required to manually feed touch events to glide in order for it to work. The problem with WPF is, that there is not a method known to use on how to feed these touch events to WPF. There was an issue reported to Microsoft (http://netmf.codeplex.com/workitem/1745) relating to this issue, but it has since been closed, without resolution. You may attempt to re-report the issue or you may use Glide, with the following code to feed the touch events to Glide:

void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
        {
            GHIElectronics.NETMF.Glide.Geom.Point touches;
            if (touchStatus.numTouches > 0)
            {
                touches.X = touchStatus.touchPos[0].xPos;
                touches.Y = touchStatus.touchPos[0].yPos;
                x = 0;
                y = 0;
                if (isTouched == false)
                {
                    GlideTouch.RaiseTouchDownEvent(null, new TouchEventArgs(touches));
                    lastX = x;
                    lastY = y;
                    isTouched = true;
                }
                else
                {
                    if (lastX != touches.X && lastY != touches.Y)
                    {
                        touches.X = lastX;
                        touches.Y = lastY;
                        GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
                        isTouched = false;
                    }
                }
            }
            else
            {
                if (isTouched == true)
                {
                    touches.X = lastX;
                    touches.Y = lastY;
                    GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
                    isTouched = false;
                }
            }
        }