Example #1
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            this.UnSubscribeEvents();

            this.DropDownPopup = this.GetTemplateChild("PART_Popup") as Popup;

            if (this.DropDownPopup is not null)
            {
                KeyboardNavigation.SetDirectionalNavigation(this.DropDownPopup, KeyboardNavigationMode.Cycle);
                KeyboardNavigation.SetTabNavigation(this.DropDownPopup, KeyboardNavigationMode.Continue);
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;

            this.scrollViewer = this.GetTemplateChild("PART_ScrollViewer") as ScrollViewer;

            this.buttonBorder = this.GetTemplateChild("PART_ButtonBorder") as UIElement;

            this.dropDownBorder = this.GetTemplateChild("PART_DropDownBorder") as Border;

            base.OnApplyTemplate();

            this.SubscribeEvents();
        }
Example #2
0
        private Tuple <Thumb?, IDisposable> SelectAndSubscribeToThumb()
        {
            var templateThumb = GetTemplateChild(ThumbPartName) as Thumb;

            templateThumb?.SetCurrentValue(IsHitTestVisibleProperty, _customThumb == null);

            _thumb = _customThumb ?? templateThumb;
            if (_thumb != null)
            {
                _thumb.DragStarted   += ThumbOnDragStarted;
                _thumb.DragDelta     += ThumbOnDragDelta;
                _thumb.DragCompleted += ThumbOnDragCompleted;
            }

            var tidyUpThumb = _thumb;
            var disposable  = Disposable.Create(() =>
            {
                if (tidyUpThumb == null)
                {
                    return;
                }
                tidyUpThumb.DragStarted   -= ThumbOnDragStarted;
                tidyUpThumb.DragDelta     -= ThumbOnDragDelta;
                tidyUpThumb.DragCompleted -= ThumbOnDragCompleted;
            });

            return(new Tuple <Thumb?, IDisposable>(_thumb, disposable));
        }
        public override void paint(
            PaintingContext context,
            Offset center,
            Animation <float> activationAnimation = null,
            Animation <float> enableAnimation     = null,
            bool isDiscrete             = false,
            bool isEnabled              = false,
            bool?isOnTop                = null,
            TextDirection?textDirection = null,
            SliderThemeData sliderTheme = null,
            Thumb?thumb = null
            )
        {
            Canvas     canvas     = context.canvas;
            ColorTween colorTween = new ColorTween(
                begin: sliderTheme.disabledThumbColor,
                end: sliderTheme.thumbColor
                );

            float size      = _thumbSize * sizeTween.evaluate(enableAnimation);
            Path  thumbPath = null;

            switch (textDirection)
            {
            case TextDirection.rtl:
                switch (thumb)
                {
                case Thumb.start:
                    thumbPath = SliderDemoUtils._rightTriangle(size, center);
                    break;

                case Thumb.end:
                    thumbPath = SliderDemoUtils._leftTriangle(size, center);
                    break;
                }

                break;

            case TextDirection.ltr:
                switch (thumb)
                {
                case Thumb.start:
                    thumbPath = SliderDemoUtils._leftTriangle(size, center);
                    break;

                case Thumb.end:
                    thumbPath = SliderDemoUtils._rightTriangle(size, center);
                    break;
                }

                break;
            }

            canvas.drawPath(thumbPath, new Paint {
                color = colorTween.evaluate(enableAnimation)
            });
        }
Example #4
0
 private void MoveThumb(Canvas?canvas, Thumb?thumb, double x, double y)
 {
     if (canvas != null && thumb != null)
     {
         double left = Clamp(x, 0, canvas.Bounds.Width);
         double top  = Clamp(y, 0, canvas.Bounds.Height);
         Canvas.SetLeft(thumb, left);
         Canvas.SetTop(thumb, top);
     }
 }
Example #5
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            this.dropDownButton = this.GetTemplateChild("PART_ToggleButton") as ToggleButton;
            if (this.dropDownButton is ISimplifiedStateControl control)
            {
                control.UpdateSimplifiedState(this.IsSimplified);
            }

            this.DropDownPopup = this.GetTemplateChild("PART_Popup") as Popup;

            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta -= this.OnResizeVerticalDelta;
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;
            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta += this.OnResizeVerticalDelta;
            }

            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta -= this.OnResizeBothDelta;
            }

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;
            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta += this.OnResizeBothDelta;
            }

            this.menuPanel = this.GetTemplateChild("PART_MenuPanel") as Panel;

            this.snappedImage = this.GetTemplateChild("PART_SelectedImage") as Image;
            this.contentSite  = this.GetTemplateChild("PART_ContentSite") as ContentPresenter;

            if (this.contentBorder is not null)
            {
                this.contentBorder.PreviewMouseDown -= this.OnContentBorderPreviewMouseDown;
            }

            this.contentBorder = this.GetTemplateChild("PART_ContentBorder") as Border;
            if (this.contentBorder is not null)
            {
                this.contentBorder.PreviewMouseDown += this.OnContentBorderPreviewMouseDown;
            }

            this.scrollViewer = this.GetTemplateChild("PART_ScrollViewer") as ScrollViewer;

            this.dropDownBorder = this.GetTemplateChild("PART_DropDownBorder") as Border;

            base.OnApplyTemplate();
        }
Example #6
0
        protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
        {
            base.OnApplyTemplate(e);

            _thumb = e.NameScope.Find <Thumb>("thumb");

            if (ToolTip.GetTip(_thumb) is ToolTip toolTip)
            {
                toolTip.Content = GetToolTipString();
            }
        }
Example #7
0
        protected void OnDragCompleted(DragCompletedEventArgs e)
        {
            var args = new DragablzDragCompletedEventArgs(DragCompleted, this, e);

            RaiseEvent(args);

            //OK, this is a cheeky bit.  A completed drag may have occured after a tab as been pushed
            //intom a new window, which means we may have reverted to the template thumb.  So, let's
            //refresh the thumb in case the user has a custom one
            _customThumb = FindCustomThumb();
            _templateSubscriptions.Disposable = SelectAndSubscribeToThumb().Item2;
        }
        void _handleDragUpdate(DragUpdateDetails details)
        {
            float dragValue = _getValueFromGlobalPosition(details.globalPosition);

            bool shouldCallOnChangeStart = false;

            if (_lastThumbSelection == null)
            {
                _lastThumbSelection = sliderTheme.thumbSelector(textDirection.Value, values, dragValue, _thumbSize,
                                                                size, details.delta.dx);
                if (_lastThumbSelection != null)
                {
                    shouldCallOnChangeStart = true;
                    _active = true;
                    _state.overlayController.forward();
                    if (showValueIndicator)
                    {
                        _state.valueIndicatorController.forward();
                    }
                }
            }

            if (isEnabled && _lastThumbSelection != null)
            {
                RangeValues currentValues = _discretizeRangeValues(values);
                if (onChangeStart != null && shouldCallOnChangeStart)
                {
                    onChangeStart(currentValues);
                }

                float currentDragValue = _discretize(dragValue);

                float minThumbSeparationValue =
                    isDiscrete ? 0 : sliderTheme.minThumbSeparation.Value / _trackRect.width;
                if (_lastThumbSelection == Thumb.start)
                {
                    _newValues =
                        new RangeValues(Mathf.Min(currentDragValue, currentValues.end - minThumbSeparationValue),
                                        currentValues.end);
                }
                else if (_lastThumbSelection == Thumb.end)
                {
                    _newValues = new RangeValues(currentValues.start,
                                                 Mathf.Max(currentDragValue, currentValues.start + minThumbSeparationValue));
                }

                onChanged(_newValues);
            }
        }
        void _startInteraction(Offset globalPosition)
        {
            float tapValue = _getValueFromGlobalPosition(globalPosition).clamp(0.0f, 1.0f);

            _lastThumbSelection = sliderTheme.thumbSelector(textDirection.Value, values, tapValue, _thumbSize, size, 0);

            if (_lastThumbSelection != null)
            {
                _active = true;
                RangeValues currentValues = _discretizeRangeValues(values);
                if (_lastThumbSelection == Thumb.start)
                {
                    _newValues = new RangeValues(tapValue, currentValues.end);
                }
                else if (_lastThumbSelection == Thumb.end)
                {
                    _newValues = new RangeValues(currentValues.start, tapValue);
                }

                _updateLabelPainter(_lastThumbSelection.Value);

                if (onChangeStart != null)
                {
                    onChangeStart(currentValues);
                }

                onChanged(_discretizeRangeValues(_newValues));

                _state.overlayController.forward();
                if (showValueIndicator)
                {
                    _state.valueIndicatorController.forward();
                    _state.interactionTimer?.cancel();
                    _state.interactionTimer =
                        Timer.create(
                            new TimeSpan(0, 0, 0, 0,
                                         (int)(_minimumInteractionTime.TotalMilliseconds * scheduler_.timeDilation)), () => {
                        _state.interactionTimer = null;
                        if (!_active && _state.valueIndicatorController.status == AnimationStatus.completed)
                        {
                            _state.valueIndicatorController.reverse();
                        }
                    });
                }
            }
        }
Example #10
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            if (this.DropDownPopup is not null)
            {
                this.DropDownPopup.Opened -= this.OnDropDownOpened;
                this.DropDownPopup.Closed -= this.OnDropDownClosed;
            }

            this.DropDownPopup = this.GetTemplateChild("PART_Popup") as Popup;

            if (this.DropDownPopup is not null)
            {
                this.DropDownPopup.Opened += this.OnDropDownOpened;
                this.DropDownPopup.Closed += this.OnDropDownClosed;

                KeyboardNavigation.SetControlTabNavigation(this.DropDownPopup, KeyboardNavigationMode.Cycle);
                KeyboardNavigation.SetDirectionalNavigation(this.DropDownPopup, KeyboardNavigationMode.Cycle);
                KeyboardNavigation.SetTabNavigation(this.DropDownPopup, KeyboardNavigationMode.Cycle);
            }

            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta -= this.OnResizeVerticalDelta;
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;
            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta += this.OnResizeVerticalDelta;
            }

            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta -= this.OnResizeBothDelta;
            }

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;
            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta += this.OnResizeBothDelta;
            }

            this.scrollViewer = this.GetTemplateChild("PART_ScrollViewer") as ScrollViewer;
            this.menuPanel    = this.GetTemplateChild("PART_MenuPanel") as Panel;
        }
Example #11
0
        /// <summary>
        /// Decides which (if any) thumb is touched by the given x-coordinate.
        /// </summary>
        /// <param name="touchX">The x-coordinate of a touch ev in screen space.</param>
        /// <returns>The pressed thumb or null if none has been touched.</returns>
        private Thumb?EvalPressedThumb(float touchX)
        {
            Thumb?result          = null;
            var   minThumbPressed = IsInThumbRange(touchX, NormalizedMinValue);
            var   maxThumbPressed = IsInThumbRange(touchX, NormalizedMaxValue);

            if (minThumbPressed && maxThumbPressed)
            {
                // if both thumbs are pressed (they lie on top of each other), choose the one with more room to drag. this avoids "stalling" the thumbs in a corner, not being able to drag them apart anymore.
                result = touchX / Width > 0.5f ? Thumb.Lower : Thumb.Upper;
            }
            else if (minThumbPressed)
            {
                result = Thumb.Lower;
            }
            else if (maxThumbPressed)
            {
                result = Thumb.Upper;
            }
            return(result);
        }
Example #12
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta -= this.OnResizeVerticalDelta;
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;
            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta += this.OnResizeVerticalDelta;
            }

            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta -= this.OnResizeBothDelta;
            }

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;
            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta += this.OnResizeBothDelta;
            }
        }
        public override void OnApplyTemplate()
#endif
        {
            base.OnApplyTemplate();

            SliderTrack = GetTemplateChild(nameof(SliderTrack)) as FrameworkElement;
            if (SliderTrack != null)
            {
                SliderTrack.SizeChanged += TimeSlider_SizeChanged;
            }

            HorizontalTrackThumb           = GetTemplateChild(nameof(HorizontalTrackThumb)) as Thumb;
            MinimumThumb                   = GetTemplateChild(nameof(MinimumThumb)) as Thumb;
            MinimumThumbLabel              = GetTemplateChild(nameof(MinimumThumbLabel)) as TextBlock;
            MaximumThumb                   = GetTemplateChild(nameof(MaximumThumb)) as Thumb;
            MaximumThumbLabel              = GetTemplateChild(nameof(MaximumThumbLabel)) as TextBlock;
            SliderTrackStepBackRepeater    = GetTemplateChild(nameof(SliderTrackStepBackRepeater)) as RepeatButton;
            SliderTrackStepForwardRepeater = GetTemplateChild(nameof(SliderTrackStepForwardRepeater)) as RepeatButton;
            PlayPauseButton                = GetTemplateChild(nameof(PlayPauseButton)) as ToggleButton;
            NextButton               = GetTemplateChild(nameof(NextButton)) as ButtonBase;
            PreviousButton           = GetTemplateChild(nameof(PreviousButton)) as ButtonBase;
            Tickmarks                = GetTemplateChild(nameof(Tickmarks)) as Primitives.Tickbar;
            FullExtentStartTimeLabel = GetTemplateChild(nameof(FullExtentStartTimeLabel)) as TextBlock;
            FullExtentEndTimeLabel   = GetTemplateChild(nameof(FullExtentEndTimeLabel)) as TextBlock;

            if (MinimumThumb != null)
            {
#if NETFX_CORE
                MinimumThumb.ManipulationMode   = ManipulationModes.TranslateX;
                MinimumThumb.ManipulationDelta += (s, e) =>
                {
                    // Position is reported relative to the left edge of the thumb.  Adjust it so it is relative to the thumb's center.
                    var translateX = e.Position.X - (MinimumThumb.ActualWidth / 2);
                    OnMinimumThumbDrag(translateX);
                };
#else
                MinimumThumb.DragDelta += (s, e) => OnMinimumThumbDrag(e.HorizontalChange);
#endif
                MinimumThumb.DragCompleted += (s, e) => OnDragCompleted();
                MinimumThumb.DragStarted   += (s, e) => SetFocus();
            }

            if (MaximumThumb != null)
            {
#if NETFX_CORE
                MaximumThumb.ManipulationMode   = ManipulationModes.TranslateX;
                MaximumThumb.ManipulationDelta += (s, e) =>
                {
                    // Position is reported relative to the left edge of the thumb.  Adjust it so it is relative to the thumb's center.
                    var translateX = e.Position.X - (MaximumThumb.ActualWidth / 2);
                    OnMaximumThumbDrag(translateX);
                };
#else
                MaximumThumb.DragDelta += (s, e) => OnMaximumThumbDrag(e.HorizontalChange);
#endif
                MaximumThumb.DragCompleted += (s, e) => OnDragCompleted();
                MaximumThumb.DragStarted   += (s, e) => SetFocus();
            }

            if (HorizontalTrackThumb != null)
            {
#if NETFX_CORE
                HorizontalTrackThumb.ManipulationMode   = ManipulationModes.TranslateX;
                HorizontalTrackThumb.ManipulationDelta += (s, e) =>
                {
                    // Position is reported relative to the left edge of the thumb.  Adjust it so it is relative to the thumb's center.
                    var translateX = e.Position.X - (HorizontalTrackThumb.ActualWidth / 2);
                    OnCurrentExtentThumbDrag(translateX);
                };
#else
                HorizontalTrackThumb.DragDelta += (s, e) => OnCurrentExtentThumbDrag(e.HorizontalChange);
#endif
                HorizontalTrackThumb.DragCompleted += (s, e) => OnDragCompleted();
                HorizontalTrackThumb.DragStarted   += (s, e) => SetFocus();
            }

            if (SliderTrackStepBackRepeater != null)
            {
                SliderTrackStepBackRepeater.Click += (s, e) =>
                {
                    SetFocus();
                    IsPlaying = false;
                    StepBack();
                };
            }

            if (SliderTrackStepForwardRepeater != null)
            {
                SliderTrackStepForwardRepeater.Click += (s, e) =>
                {
                    SetFocus();
                    IsPlaying = false;
                    StepForward();
                };
            }

            if (PlayPauseButton != null)
            {
                IsPlaying = PlayPauseButton.IsChecked.HasValue && PlayPauseButton.IsChecked.Value;
                PlayPauseButton.Checked   += (s, e) => IsPlaying = true;
                PlayPauseButton.Unchecked += (s, e) => IsPlaying = false;
            }

            if (NextButton != null)
            {
                NextButton.Click += (s, e) => OnNextButtonClick();
            }

            if (PreviousButton != null)
            {
                PreviousButton.Click += (s, e) => OnPreviousButtonClick();
            }

            PositionTickmarks();
            SetButtonVisibility();
            ApplyLabelMode(LabelMode);
        }
Example #14
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            if (_colorCanvas != null)
            {
                _colorCanvas.PointerPressed  -= ColorCanvas_PointerPressed;
                _colorCanvas.PointerReleased -= ColorCanvas_PointerReleased;
                _colorCanvas.PointerMoved    -= ColorCanvas_PointerMoved;
            }

            if (_colorThumb != null)
            {
                _colorThumb.DragDelta -= ColorThumb_DragDelta;
            }

            if (_hueCanvas != null)
            {
                _hueCanvas.PointerPressed  -= HueCanvas_PointerPressed;
                _hueCanvas.PointerReleased -= HueCanvas_PointerReleased;
                _hueCanvas.PointerMoved    -= HueCanvas_PointerMoved;
            }

            if (_hueThumb != null)
            {
                _hueThumb.DragDelta -= HueThumb_DragDelta;
            }

            if (_alphaCanvas != null)
            {
                _alphaCanvas.PointerPressed  -= AlphaCanvas_PointerPressed;
                _alphaCanvas.PointerReleased -= AlphaCanvas_PointerReleased;
                _alphaCanvas.PointerMoved    -= AlphaCanvas_PointerMoved;
            }

            if (_alphaThumb != null)
            {
                _alphaThumb.DragDelta -= AlphaThumb_DragDelta;
            }

            _colorCanvas = e.NameScope.Find <Canvas>("PART_ColorCanvas");
            _colorThumb  = e.NameScope.Find <Thumb>("PART_ColorThumb");
            _hueCanvas   = e.NameScope.Find <Canvas>("PART_HueCanvas");
            _hueThumb    = e.NameScope.Find <Thumb>("PART_HueThumb");
            _alphaCanvas = e.NameScope.Find <Canvas>("PART_AlphaCanvas");
            _alphaThumb  = e.NameScope.Find <Thumb>("PART_AlphaThumb");

            if (_colorCanvas != null)
            {
                _colorCanvas.PointerPressed  += ColorCanvas_PointerPressed;
                _colorCanvas.PointerReleased += ColorCanvas_PointerReleased;
                _colorCanvas.PointerMoved    += ColorCanvas_PointerMoved;
            }

            if (_colorThumb != null)
            {
                _colorThumb.DragDelta += ColorThumb_DragDelta;
            }

            if (_hueCanvas != null)
            {
                _hueCanvas.PointerPressed  += HueCanvas_PointerPressed;
                _hueCanvas.PointerReleased += HueCanvas_PointerReleased;
                _hueCanvas.PointerMoved    += HueCanvas_PointerMoved;
            }

            if (_hueThumb != null)
            {
                _hueThumb.DragDelta += HueThumb_DragDelta;
            }

            if (_alphaCanvas != null)
            {
                _alphaCanvas.PointerPressed  += AlphaCanvas_PointerPressed;
                _alphaCanvas.PointerReleased += AlphaCanvas_PointerReleased;
                _alphaCanvas.PointerMoved    += AlphaCanvas_PointerMoved;
            }

            if (_alphaThumb != null)
            {
                _alphaThumb.DragDelta += AlphaThumb_DragDelta;
            }
        }
Example #15
0
        /// <summary>
        ///     Handles thumb selection and movement. Notifies listener callback on certain evs.
        /// </summary>
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (!Enabled)
            {
                return(false);
            }

            int pointerIndex;

            var action = ev.Action;

            switch (action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
                // Remember where the motion ev started
                _activePointerId = ev.GetPointerId(ev.PointerCount - 1);
                pointerIndex     = ev.FindPointerIndex(_activePointerId);
                _downMotionX     = ev.GetX(pointerIndex);

                _pressedThumb = EvalPressedThumb(_downMotionX);

                // Only handle thumb presses.
                if (_pressedThumb == null)
                {
                    return(base.OnTouchEvent(ev));
                }

                Pressed = true;
                Invalidate();
                OnStartTrackingTouch();
                TrackTouchEvent(ev, StepValueContinuously);
                AttemptClaimDrag();

                break;

            case MotionEventActions.Move:
                if (_pressedThumb != null)
                {
                    if (_isDragging)
                    {
                        TrackTouchEvent(ev, StepValueContinuously);
                    }
                    else
                    {
                        // Scroll to follow the motion ev
                        pointerIndex = ev.FindPointerIndex(_activePointerId);
                        var x = ev.GetX(pointerIndex);

                        if (Math.Abs(x - _downMotionX) > _scaledTouchSlop)
                        {
                            Pressed = true;
                            Invalidate();
                            OnStartTrackingTouch();
                            TrackTouchEvent(ev, StepValueContinuously);
                            AttemptClaimDrag();
                        }
                    }

                    if (NotifyWhileDragging)
                    {
                        if (_pressedThumb == Thumb.Lower)
                        {
                            OnLowerValueChanged();
                        }
                        if (_pressedThumb == Thumb.Upper)
                        {
                            OnUpperValueChanged();
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
                if (_isDragging)
                {
                    TrackTouchEvent(ev, true);
                    OnStopTrackingTouch();
                    Pressed = false;
                }
                else
                {
                    // Touch up when we never crossed the touch slop threshold
                    // should be interpreted as a tap-seek to that location.
                    OnStartTrackingTouch();
                    TrackTouchEvent(ev, true);
                    OnStopTrackingTouch();
                }
                if (_pressedThumb == Thumb.Lower)
                {
                    OnLowerValueChanged();
                }
                if (_pressedThumb == Thumb.Upper)
                {
                    OnUpperValueChanged();
                }
                _pressedThumb = null;
                Invalidate();
                break;

            case MotionEventActions.PointerDown:
                var index = ev.PointerCount - 1;
                // readonly int index = ev.getActionIndex();
                _downMotionX     = ev.GetX(index);
                _activePointerId = ev.GetPointerId(index);
                Invalidate();
                break;

            case MotionEventActions.PointerUp:
                OnSecondaryPointerUp(ev);
                Invalidate();
                break;

            case MotionEventActions.Cancel:
                if (_isDragging)
                {
                    OnStopTrackingTouch();
                    Pressed = false;
                }
                Invalidate();     // see above explanation
                break;
            }
            return(true);
        }
Example #16
0
        protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
        {
            if (colorCanvas != null)
            {
                colorCanvas.PointerPressed  -= ColorCanvas_PointerPressed;
                colorCanvas.PointerReleased -= ColorCanvas_PointerReleased;
                colorCanvas.PointerMoved    -= ColorCanvas_PointerMoved;
            }

            if (colorThumb != null)
            {
                colorThumb.DragDelta -= ColorThumb_DragDelta;
            }

            if (hueCanvas != null)
            {
                hueCanvas.PointerPressed  -= HueCanvas_PointerPressed;
                hueCanvas.PointerReleased -= HueCanvas_PointerReleased;
                hueCanvas.PointerMoved    -= HueCanvas_PointerMoved;
            }

            if (hueThumb != null)
            {
                hueThumb.DragDelta -= HueThumb_DragDelta;
            }

            if (alphaCanvas != null)
            {
                alphaCanvas.PointerPressed  -= AlphaCanvas_PointerPressed;
                alphaCanvas.PointerReleased -= AlphaCanvas_PointerReleased;
                alphaCanvas.PointerMoved    -= AlphaCanvas_PointerMoved;
            }

            if (alphaThumb != null)
            {
                alphaThumb.DragDelta -= AlphaThumb_DragDelta;
            }

            colorCanvas = e.NameScope.Find <Canvas>("PART_ColorCanvas");
            colorThumb  = e.NameScope.Find <Thumb>("PART_ColorThumb");
            hueCanvas   = e.NameScope.Find <Canvas>("PART_HueCanvas");
            hueThumb    = e.NameScope.Find <Thumb>("PART_HueThumb");
            alphaCanvas = e.NameScope.Find <Canvas>("PART_AlphaCanvas");
            alphaThumb  = e.NameScope.Find <Thumb>("PART_AlphaThumb");

            if (colorCanvas != null)
            {
                colorCanvas.PointerPressed  += ColorCanvas_PointerPressed;
                colorCanvas.PointerReleased += ColorCanvas_PointerReleased;
                colorCanvas.PointerMoved    += ColorCanvas_PointerMoved;
            }

            if (colorThumb != null)
            {
                colorThumb.DragDelta += ColorThumb_DragDelta;
            }

            if (hueCanvas != null)
            {
                hueCanvas.PointerPressed  += HueCanvas_PointerPressed;
                hueCanvas.PointerReleased += HueCanvas_PointerReleased;
                hueCanvas.PointerMoved    += HueCanvas_PointerMoved;
            }

            if (hueThumb != null)
            {
                hueThumb.DragDelta += HueThumb_DragDelta;
            }

            if (alphaCanvas != null)
            {
                alphaCanvas.PointerPressed  += AlphaCanvas_PointerPressed;
                alphaCanvas.PointerReleased += AlphaCanvas_PointerReleased;
                alphaCanvas.PointerMoved    += AlphaCanvas_PointerMoved;
            }

            if (alphaThumb != null)
            {
                alphaThumb.DragDelta += AlphaThumb_DragDelta;
            }
        }
Example #17
0
        protected override void OnApplyTemplate()
        {
            if (_tpThumb != null)
            {
                _dragStarted.Disposable   = null;
                _dragDelta.Disposable     = null;
                _dragCompleted.Disposable = null;
                _tap.Disposable           = null;
            }

            if (_tpKnob != null)
            {
                _knobSizeChanged.Disposable = null;
            }

            if (_tpKnobBounds != null)
            {
                _knobBoundsSizeChanged.Disposable = null;
            }

            _tpCurtainBounds    = null;
            _tpCurtainClip      = null;
            _spCurtainTransform = null;
            _tpKnob             = null;
            _tpKnobBounds       = null;
            _spKnobTransform    = null;
            _tpThumb            = null;
            _tpHeaderPresenter  = null;

            base.OnApplyTemplate();

            var spCurtainIDependencyObject       = GetTemplateChild("SwitchCurtain");
            var spCurtainBoundsIDependencyObject = GetTemplateChild("SwitchCurtainBounds");
            var spCurtainClipIDependencyObject   = GetTemplateChild("SwitchCurtainClip");
            var spKnobIDependencyObject          = GetTemplateChild("SwitchKnob");
            var spKnobBoundsIDependencyObject    = GetTemplateChild("SwitchKnobBounds");
            var spThumbIDependencyObject         = GetTemplateChild("SwitchThumb");

            _tpCurtainBounds = spCurtainBoundsIDependencyObject as FrameworkElement;
            _tpCurtainClip   = spCurtainClipIDependencyObject as UIElement;
            _tpKnob          = spKnobIDependencyObject as FrameworkElement;
            _tpKnobBounds    = spKnobBoundsIDependencyObject as FrameworkElement;
            _tpThumb         = spThumbIDependencyObject as Thumb;

            var spThumbIUIElement = _tpThumb as UIElement;

            var spCurtainIUIElement = spCurtainIDependencyObject as UIElement;

            if (spCurtainIUIElement != null)
            {
                var spCurtainRenderTransform = spCurtainIUIElement.RenderTransform;
                _spCurtainTransform = spCurtainRenderTransform as TranslateTransform;
            }

            var spKnobIUIElement = spKnobIDependencyObject as UIElement;

            if (spKnobIUIElement != null)
            {
                Transform spKnobRenderTransform = spKnobIUIElement.RenderTransform;
                _spKnobTransform = spKnobRenderTransform as TranslateTransform;
            }

            if (spThumbIUIElement != null && _tpThumb != null)
            {
                _tpThumb.DragStarted     += DragStartedHandler;
                _dragStarted.Disposable   = Disposable.Create(() => _tpThumb.DragStarted -= DragStartedHandler);
                _tpThumb.DragDelta       += DragDeltaHandler;
                _dragDelta.Disposable     = Disposable.Create(() => _tpThumb.DragDelta -= DragDeltaHandler);
                _tpThumb.DragCompleted   += DragCompletedHandler;
                _dragCompleted.Disposable = Disposable.Create(() => _tpThumb.DragCompleted -= DragCompletedHandler);
                spThumbIUIElement.Tapped += TapHandler;
                _tap.Disposable           = Disposable.Create(() => spThumbIUIElement.Tapped -= TapHandler);
            }

            if (_tpKnob != null || _tpKnobBounds != null)
            {
                if (_tpKnob != null)
                {
                    _tpKnob.SizeChanged        += SizeChangedHandler;
                    _knobSizeChanged.Disposable = Disposable.Create(() => _tpKnob.SizeChanged -= SizeChangedHandler);
                }

                if (_tpKnobBounds != null)
                {
                    _tpKnobBounds.SizeChanged        += SizeChangedHandler;
                    _knobBoundsSizeChanged.Disposable = Disposable.Create(() => _tpKnobBounds.SizeChanged -= SizeChangedHandler);
                }
            }

            UpdateHeaderPresenterVisibility();

            UpdateVisualState(false);
        }