Beispiel #1
0
        protected override void OnAttached()
        {
            base.OnAttached();

            CanRotate     = true;
            CanTranslate  = true;
            CanScale      = true;
            CanManipulate = true;

            _manipulationProcessor            = new ManipulationProcessor2D(Manipulations2D.All);
            _manipulationProcessor.Started   += OnManipulationStarted;
            _manipulationProcessor.Delta     += OnManipulationDelta;
            _manipulationProcessor.Completed += OnManipulationCompleted;

            TouchHelper.AddHandlers(AssociatedObject, new TouchHandlers
            {
                TouchDown             = OnTouchDown,
                CapturedTouchReported = OnCapturedTouchReported
            });
            TouchHelper.EnableInput(true);
            TouchHelper.SetRootElement(TouchHelper.GetRootElement(AssociatedObject));

            _renderTransform = AssociatedObject.RenderTransform as CompositeTransform;
            if (_renderTransform == null)
            {
                _renderTransform = new CompositeTransform();
                AssociatedObject.RenderTransform = _renderTransform;
            }
        }
Beispiel #2
0
        protected override void OnDetaching()
        {
            base.OnDetaching();

            _manipulationProcessor.Started   -= OnManipulationStarted;
            _manipulationProcessor.Delta     -= OnManipulationDelta;
            _manipulationProcessor.Completed -= OnManipulationCompleted;

            TouchHelper.RemoveHandlers(AssociatedObject);
        }
Beispiel #3
0
        private void OnCapturedTouchReported(object sender, TouchReportedEventArgs e)
        {
            var parent = AssociatedObject.Parent as UIElement;

            if (parent == null)
            {
                return;
            }

            var root = TouchHelper.GetRootElement(parent);

            if (root == null)
            {
                return;
            }

            List <Manipulator2D> manipulators = null;

            if (e.TouchPoints.FirstOrDefault() != null)
            {
                // Get transformation to convert positions to the parent's coordinate system.
                var transform = root.TransformToVisual(parent);
                foreach (var touchPoint in e.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);
                }
            }

            // Process manipulations.
            _manipulationProcessor.ProcessManipulators(DateTime.UtcNow.Ticks, manipulators);
        }