Пример #1
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);
        }
Пример #2
0
        private void OnThumbPointerPressed(object sender, PointerRoutedEventArgs e)
        {
            Thumb thumb = sender as Thumb;

            if (thumb != null && thumb.IsTabStop)
            {
                if (thumb.FocusState == FocusState.Unfocused)
                {
                    thumb.Focus(FocusState.Programmatic);
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
        void OnClickOnSmallOrLargeDecreaseIncreaseButtons(double amountByWhichToIncreaseOrDecreaseTheValue, ScrollEventType scrollEventType)
        {
            double newValue = CoerceValue(this.Value + amountByWhichToIncreaseOrDecreaseTheValue);

            if (newValue != this.Value)
            {
                this.SetCurrentValue(RangeBase.ValueProperty, newValue); // Note: we do not use "this.Value = newValue" because it deletes any bindings that the user may have set to the scrollbar with <ScrollBar Value="{Binding...}"/>.
                if (this.Scroll != null)
                {
                    this.Scroll(this, new ScrollEventArgs(newValue, scrollEventType));
                }
            }

            if (Orientation == Orientation.Horizontal)
            {
                _horizontalThumb.Focus();
            }
            else
            {
                _verticalThumb.Focus();
            }
        }