Esempio n. 1
0
        /// <summary>
        /// 设置界面的滑块的移动方式
        /// </summary>
        /// <param name="thumb">滑块</param>
        /// <param name="e">事件对象</param>
        /// <param name="lBorder">左边界</param>
        /// <param name="rBorder">右边界</param>
        private void OptionThumbDrug(Thumb thumb, DragDeltaEventArgs e, double lBorder, double rBorder)
        {
            double x = Canvas.GetLeft(thumb);

            Canvas.SetLeft(thumb, x + e.HorizontalChange);      //令thumb跟随鼠标移动
            if (x < lBorder)
            {
                thumb.CancelDrag();             //删除thumb的鼠标捕获并触发DragComplete事件
                Canvas.SetLeft(thumb, lBorder); //防止thumb停在界外,下同
            }
            if (x > rBorder)
            {
                thumb.CancelDrag();
                Canvas.SetLeft(thumb, rBorder);
            }
        }
Esempio n. 2
0
        public void DefaultMethods()
        {
            Thumb t = new Thumb();

            t.CancelDrag();
            t.OnApplyTemplate();
            ControlTest.CheckDefaultMethods(t);
        }
Esempio n. 3
0
        private bool SetValueStartDrag(
            Func <IInputElement, Point> getPosition,
            Action <UIElement> captureDevice)
        {
            if (!_canDrag)
            {
                return(false);
            }

            try
            {
                _isDragStarting = true;

                var originTrackPoint = getPosition(_track);
                var newValue         = _track.ValueFromPoint(originTrackPoint);
                newValue = Math.Min(this.Maximum, Math.Max(this.Minimum, Math.Round(newValue)));

                if (newValue == this.Value)
                {
                    return(false);
                }

                // Set new value.
                _updateValue.Invoke(this, new object[] { newValue });
            }
            finally
            {
                _isDragStarting = false;
            }

            // Reproduce Thumb.OnMouseLeftButtonDown method.
            if (!_thumb.IsDragging)
            {
                // Start drag operation for Thumb.
                _thumb.Focus();
                captureDevice(_thumb);

                _thumbIsDragging.SetValue(_thumb, true);

                var originThumbPoint         = getPosition(_thumb);
                var originThumbPointToScreen = _thumb.PointToScreen(originThumbPoint);
                //_thumbOriginThumbPoint.SetValue(_thumb, originThumbPoint);
                _thumbPreviousScreenCoordPosition.SetValue(_thumb, originThumbPointToScreen);
                _thumbOriginScreenCoordPosition.SetValue(_thumb, originThumbPointToScreen);

                try
                {
                    _thumb.RaiseEvent(new DragStartedEventArgs(originThumbPoint.X, originThumbPoint.Y));
                }
                catch
                {
                    _thumb.CancelDrag();
                    throw;
                }
            }
            return(true);
        }
Esempio n. 4
0
        protected virtual bool SetValueStartDrag(
            Func <IInputElement, Point> getPosition,
            Action <UIElement> captureDevice)
        {
            if (!CanDrag)
            {
                return(false);
            }

            if (!this.IsFocused)
            {
                this.Focus();
            }

            var originTrackPoint = getPosition(_track);
            var newValue         = _track.ValueFromPoint(originTrackPoint);

            if (UpdateValue(newValue))
            {
                return(false);
            }

            // Reproduce Thumb.OnMouseLeftButtonDown method.
            if (!_thumb.IsDragging)
            {
                // Start drag operation for Thumb.
                _thumb.Focus();
                captureDevice(_thumb);

                _thumbIsDragging.SetValue(_thumb, true);

                var originThumbPoint         = getPosition(_thumb);
                var originThumbPointToScreen = _thumb.PointToScreen(originThumbPoint);
                //_thumbOriginThumbPoint.SetValue(_thumb, originThumbPoint);
                _thumbPreviousScreenCoordPosition.SetValue(_thumb, originThumbPointToScreen);
                _thumbOriginScreenCoordPosition.SetValue(_thumb, originThumbPointToScreen);

                try
                {
                    // Trigger Thumb.DragStartedEvent event.
                    _thumb.RaiseEvent(new DragStartedEventArgs(originThumbPoint.X, originThumbPoint.Y));
                }
                catch
                {
                    _thumb.CancelDrag();
                    throw;
                }
            }
            return(true);
        }
Esempio n. 5
0
        public void Events()
        {
            Thumb t = new Thumb();

            t.DragStarted += delegate(object sender, DragStartedEventArgs e) {
                throw new InvalidOperationException("DragStarted");
            };
            t.DragDelta += delegate(object sender, DragDeltaEventArgs e) {
                throw new InvalidOperationException("DragDelta");
            };
            t.DragCompleted += delegate(object sender, DragCompletedEventArgs e) {
                throw new InvalidOperationException("DragCompleted");
            };
            t.CancelDrag();
        }
Esempio n. 6
0
        /// <summary>
        /// Cancels the active scrub
        /// </summary>
        public void CancelScrub()
        {
            if (pointerCaptured)
            {
                pointerReleaseAction();
                pointerReleaseAction = null;
                pointerCaptured      = false;
            }
            else if (Thumb.IsDragging)
            {
                Thumb.CancelDrag();
#if SILVERLIGHT
                Thumb.ReleaseMouseCapture();
#else
                Thumb.ReleasePointerCaptures();
#endif
            }
            UpdateScrubbingVisualState();
        }
Esempio n. 7
0
        private void FixScrollView()
        {
            // the file uploader is used in windowless mode (to avoid overlap issues, and make it display correctly in firefox
            // when initially hiding it in a display:none div), so need to do some code to fix mouse capture issues

            FrameworkElement fe = VisualTreeHelper.GetChild(fileUploader.ScrollViewer, 0) as FrameworkElement;

            if (fe != null)
            {
                //find the vertical scrollbar
                ScrollBar sb = fe.FindName("VerticalScrollBar") as ScrollBar; if (sb != null)
                {
                    //Get the scrollbar's thumbnail. This is the sucker that remains stuck in the "drag" state
                    Thumb thumb = ((FrameworkElement)VisualTreeHelper.GetChild(sb, 0)).FindName("VerticalThumb") as Thumb;

                    //cancel the operation
                    thumb.CancelDrag();
                }
            }
        }
Esempio n. 8
0
        private void HandleRotate(object sender, DragDeltaEventArgs e)
        {
            Point pos = Mouse.GetPosition(AdornedElement);

            double rotationAngle = GetAngle(_rotationCenter, pos);

            var difference = rotationAngle - _rotateTransform.Angle;

            if (_vm.IsRotateable(difference, _rotationCenter))
            {
                _rotationAngle                = GetAngle(_rotationCenter, pos);
                _rotateTransform.Angle        = _rotationAngle;
                _reverseRotateTransform.Angle = -_rotationAngle;

                _vm.RotateSelectedItems(difference, _rotationCenter);
            }
            else
            {
                _rotate.CancelDrag();
            }
        }