コード例 #1
0
        private void OnCapturedTouchReported(object sender, TouchReportedEventArgs e)
        {
            UIElement parent = this.AssociatedObject.Parent as UIElement;

            if (parent == null)
            {
                return;
            }

            //Find the root element
            UIElement root = TouchHelper.GetRootElement(parent);

            if (root == null)
            {
                return;
            }

            // get transformation to convert positions to the parent's coordinate system
            GeneralTransform     transform    = root.TransformToVisual(parent);
            List <Manipulator2D> manipulators = null;

            foreach (TouchPoint touchPoint in e.TouchPoints)
            {
                Point position = touchPoint.Position;

                // convert to the parent's coordinate system
                position = transform.Transform(position);

                // create a manipulator
                Manipulator2D manipulator = new Manipulator2D(
                    touchPoint.TouchDevice.Id,
                    (float)(position.X),
                    (float)(position.Y));

                if (manipulators == null)
                {
                    // lazy initialization
                    manipulators = new List <Manipulator2D>();
                }
                manipulators.Add(manipulator);
            }

            // process manipulations
            this.manipulationProcessor.ProcessManipulators(
                Timestamp,
                manipulators);
        }
コード例 #2
0
        /// <summary>
        /// Occurs when Touch points are reported: handles manipulations
        /// </summary>
        private void OnCapturedTouchReported(object sender, TouchReportedEventArgs e)
        {
            var parent = AssociatedObject.Parent as UIElement;

            if (parent == null)
            {
                return;
            }

            //Find the root element
            var root = TouchHelper.GetRootElement(parent);

            if (root == null)
            {
                return;
            }

            //Multi-Page support: verify if the collection of Touch points is null
            var touchPoints = e.TouchPoints;
            List <Manipulator2D> manipulators = null;

            if (touchPoints.FirstOrDefault() != null)
            {
                // get transformation to convert positions to the parent's coordinate system
                var transform = root.TransformToVisual(parent);
                foreach (var touchPoint in touchPoints)
                {
                    var position = touchPoint.Position;

                    // convert to the parent's coordinate system
                    position = transform.Transform(position);

                    // create a manipulator
                    var manipulator = new Manipulator2D(
                        touchPoint.TouchDevice.Id,
                        (float)(position.X),
                        (float)(position.Y));

                    if (manipulators == null)
                    {
                        // lazy initialization
                        manipulators = new List <Manipulator2D>();
                    }
                    manipulators.Add(manipulator);

                    //Change the visualization of the touchPoint
                    if (_touchPointsMarkers.ContainsKey(touchPoint.TouchDevice.Id))
                    {
                        if (AreFingersVisible)
                        {
                            _touchPointsMarkers[touchPoint.TouchDevice.Id].HorizontalOffset =
                                touchPoint.Position.X - (EllipseWidth / 2);
                            _touchPointsMarkers[touchPoint.TouchDevice.Id].VerticalOffset =
                                touchPoint.Position.Y - (EllipseWidth / 2);
                        }
#if DEBUG
                        Debug.WriteLine("TouchPoint Reported: Id {0} at ({1} - Total Touch Points: {2})",
                                        touchPoint.TouchDevice.Id,
                                        touchPoint.Position, touchPoints.Count());
#endif
                    }
                }
            }

            // process manipulations
            _manipulationProcessor.ProcessManipulators(Timestamp, manipulators);
        }