Exemple #1
0
        /// <summary>
        ///     Captures the specified device to this element.
        /// </summary>
        /// <param name="touchDevice">The touch device to capture.</param>
        /// <returns>True if capture was taken.</returns>
        public bool CaptureTouch(TouchDevice touchDevice)
        {
            if (touchDevice == null)
            {
                throw new ArgumentNullException("touchDevice");
            }

            return(touchDevice.Capture(this));
        }
        public static void CaptureTouchDeviceToManipulationEnabledParent(DependencyObject element, TouchDevice touchDevice)
        {
            if (element == null)
            {
                return;
            }

            UIElement parent = VisualTreeHelper.GetParent(element) as UIElement;

            if (parent == null)
            {
                touchDevice.Capture(null);
                return;
            }

            if (parent.IsManipulationEnabled)
            {
                touchDevice.Capture(parent as IInputElement);
                return;
            }

            CaptureTouchDeviceToManipulationEnabledParent(parent, touchDevice);
        }
        protected virtual bool BeginDragOperation(InputDevice deviceToCapture, Point initialDragPosition)
        {
            // This is a helper method that provides for easy dragging of the
            // LoopPanel's Offset using the Mouse. It can be overridden to provide
            // support for other input devices like a Surface Contact.
            bool result = false;

            if (CapturedDevice == null)
            {
                _lastDragPosition = initialDragPosition;
                if (deviceToCapture is MouseDevice)
                {
                    MouseDevice md = deviceToCapture as MouseDevice;

                    if (md.Captured != null)
                    {
                        md.Captured.ReleaseMouseCapture();
                    }

                    // By default, we support dragging via the left mouse button.
                    // If another button is required for dragging, this method should be overridden.
                    if (md.Captured == null && md.LeftButton == MouseButtonState.Pressed)
                    {
                        CapturedDevice = md;
                        md.Capture(this);
                        result = true;
                    }
                }
                else if (deviceToCapture is TouchDevice)
                {
                    TouchDevice td = deviceToCapture as TouchDevice;

                    if (td.Captured != null)
                    {
                        this.ReleaseTouchCapture(td);
                    }

                    // By default, we support dragging via the left touch button.
                    // If another button is required for dragging, this method should be overridden.
                    if (td.Captured == null)
                    {
                        CapturedDevice = td;
                        td.Capture(this);
                        result = true;
                    }
                }
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        ///     Releases capture from the specified touch device.
        /// </summary>
        /// <param name="touchDevice">The device that is captured to this element.</param>
        /// <returns>true if capture was released, false otherwise.</returns>
        public bool ReleaseTouchCapture(TouchDevice touchDevice)
        {
            if (touchDevice == null)
            {
                throw new ArgumentNullException("touchDevice");
            }

            if (touchDevice.Captured == this)
            {
                touchDevice.Capture(null);
                return(true);
            }
            else
            {
                return(false);
            }
        }