public SwipeEventArgs(Vector2 origPosition, Vector2 lastPosition, Vector2 lastNormalizedPosition, Vector2 delta, SwipeStatus swipeStatus, int fingerId) { this.origPosition = origPosition; this.lastPosition = lastPosition; this.lastNormalizedPosition = lastNormalizedPosition; this.delta = delta; this.swipeStatus = swipeStatus; this.fingerId = fingerId; }
/// <summary> /// Handler for when slide manipulation is underway /// </summary> private void ContentGrid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { if (SwipeStatus == SwipeStatus.Idle) { return; } var newTranslationX = _transform.TranslateX + e.Delta.Translation.X; bool swipingInDisabledArea = false; SwipeStatus newSwipeStatus = SwipeStatus.Idle; if (newTranslationX > 0) { // Swiping from left to right if (!IsLeftCommandEnabled) { // If swipe is not enabled, only allow swipe a very short distance if (newTranslationX > 0) { swipingInDisabledArea = true; newSwipeStatus = SwipeStatus.DisabledSwipingToRight; } double disabledSwipeDistance = _startcapPath.ActualWidth; if (newTranslationX > disabledSwipeDistance) { newTranslationX = disabledSwipeDistance; } } else if (IsOffsetLimited) { // If offset is limited, there will be a limit how much swipe is possible. // This will be the value of the command panel plus some threshold. // This value can't be less than the ActivationWidth. var swipeThreshold = _leftCommandPanel.ActualWidth + ExtraSwipeThreshold; if (swipeThreshold < ActivationWidth) { swipeThreshold = ActivationWidth; } if (Math.Abs(newTranslationX) > swipeThreshold) { newTranslationX = swipeThreshold; } } // Don't allow swiping more than almost the whole content grid width // (doing this will cause the control to change size). if (newTranslationX > (_contentGrid.ActualWidth - 4)) { newTranslationX = _contentGrid.ActualWidth - 4; } } else { // Swiping from right to left if (!IsRightCommandEnabled) { // If swipe is not enabled, only allow swipe a very short distance if (newTranslationX < 0) { swipingInDisabledArea = true; newSwipeStatus = SwipeStatus.DisabledSwipingToLeft; } if (newTranslationX < -16) { newTranslationX = -16; } } else if (IsOffsetLimited) { // If offset is limited, there will be a limit how much swipe is possible. // This will be the value of the command panel plus some threshold. // This value can't be less than the ActivationWidth. var swipeThreshold = _rightCommandPanel.ActualWidth + ExtraSwipeThreshold; if (swipeThreshold < ActivationWidth) { swipeThreshold = ActivationWidth; } if (Math.Abs(newTranslationX) > swipeThreshold) { newTranslationX = -swipeThreshold; } } // Don't allow swiping more than almost the whole content grid width // (doing this will cause the control to change size). if (newTranslationX < -(_contentGrid.ActualWidth + (_endcapPath?.ActualWidth ?? 0) + (_startcapPath?.ActualWidth ?? 0) - 4)) { newTranslationX = -(_contentGrid.ActualWidth + (_endcapPath?.ActualWidth ?? 0) + (_startcapPath?.ActualWidth ?? 0) - 4); } } bool hasPassedThreshold = !swipingInDisabledArea && Math.Abs(newTranslationX) >= ActivationWidth; if (swipingInDisabledArea) { // Don't show any command if swiping in disabled area. _commandContainer.Opacity = 0; _leftCommandPanel.Opacity = 0; _rightCommandPanel.Opacity = 0; } else if (newTranslationX > 0) { // If swiping from left to right, show left command panel. _rightCommandPanel.Opacity = 0; _commandContainer.Background = LeftBackground as SolidColorBrush; (_commandContainer.RenderTransform as CompositeTransform).TranslateX = _startcapPath.ActualWidth; _commandContainer.Opacity = 1; _leftCommandPanel.Opacity = 1; _commandContainer.Clip.Rect = new Rect(0, 0, Math.Max(newTranslationX - 1, 0), _commandContainer.ActualHeight); if (newTranslationX < ActivationWidth) { _leftCommandAnimationSet?.Stop(); _leftCommandPanel.RenderTransform = _leftCommandTransform; _leftCommandTransform.TranslateX = newTranslationX / 2; newSwipeStatus = SwipeStatus.SwipingToRightThreshold; } else { if (SwipeStatus == SwipeStatus.SwipingToRightThreshold) { // The control was just put below the threshold. // Run an animation to put the text and icon // in the correct position. _leftCommandAnimationSet = _leftCommandPanel.Offset((float)(LeftSnappedCommandMargin - _leftCommandTransform.TranslateX), duration: AnimationSetDuration); _leftCommandAnimationSet.Start(); } else if (SwipeStatus != SwipeStatus.SwipingPassedRightThreshold) { // This will cover extrem cases when previous state wasn't // below threshold. _leftCommandAnimationSet?.Stop(); _leftCommandPanel.RenderTransform = _leftCommandTransform; _leftCommandTransform.TranslateX = LeftSnappedCommandMargin; } newSwipeStatus = SwipeStatus.SwipingPassedRightThreshold; } } else { // If swiping from right to left, show right command panel. _leftCommandPanel.Opacity = 0; _commandContainer.Background = RightBackground as SolidColorBrush; (_commandContainer.RenderTransform as CompositeTransform).TranslateX = 0; _commandContainer.Opacity = 1; _rightCommandPanel.Opacity = 1; _commandContainer.Clip.Rect = new Rect(_commandContainer.ActualWidth + newTranslationX + 1, 0, Math.Max(-newTranslationX - 1, 0), _commandContainer.ActualHeight); if (-newTranslationX < ActivationWidth) { _rightCommandAnimationSet?.Stop(); _rightCommandPanel.RenderTransform = _rightCommandTransform; _rightCommandTransform.TranslateX = newTranslationX / 2; newSwipeStatus = SwipeStatus.SwipingToLeftThreshold; } else { if (SwipeStatus == SwipeStatus.SwipingToLeftThreshold) { // The control was just put below the threshold. // Run an animation to put the text and icon // in the correct position. _rightCommandAnimationSet = _rightCommandPanel.Offset((float)(-RightSnappedCommandMargin - _rightCommandTransform.TranslateX), duration: AnimationSetDuration); _rightCommandAnimationSet.Start(); } else if (SwipeStatus != SwipeStatus.SwipingPassedLeftThreshold) { // This will cover extrem cases when previous state wasn't // below threshold. _rightCommandAnimationSet?.Stop(); _rightCommandPanel.RenderTransform = _rightCommandTransform; _rightCommandTransform.TranslateX = -RightSnappedCommandMargin; } newSwipeStatus = SwipeStatus.SwipingPassedLeftThreshold; } } _transform.TranslateX = newTranslationX; if (newTranslationX > 0) { _endcapPathTransform.TranslateX = newTranslationX; if (newTranslationX >= _startcapPath.ActualWidth) { _startcapPathTransform.TranslateX = _startcapPath.ActualWidth; } else { _startcapPathTransform.TranslateX = newTranslationX; } } else { _startcapPathTransform.TranslateX = newTranslationX; if (_endcapPathTransform.TranslateX + newTranslationX != 0) { _endcapPathTransform.TranslateX = 0; } } SwipeStatus = newSwipeStatus; }
/// <summary> /// Handler for when slide manipulation is underway /// </summary> private void ContentGrid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { if (SwipeStatus == SwipeStatus.Idle) { return; } // var newTranslationX = _transform.TranslateX + e.Delta.Translation.X; var newTranslationY = _transform.TranslateY + e.Delta.Translation.Y; bool swipingInDisabledArea = false; SwipeStatus newSwipeStatus = SwipeStatus.Idle; if (newTranslationY > 0) { // Swiping from Top to Bottom if (!IsTopCommandEnabled) { // If swipe is not enabled, only allow swipe a very short distance if (newTranslationY > 0) { swipingInDisabledArea = true; newSwipeStatus = SwipeStatus.DisabledSwipingToBottom; } if (newTranslationY > 16) { newTranslationY = 16; } } else if (IsOffsetLimited) { // If offset is limited, there will be a limit how much swipe is possible. // This will be the value of the command panel plus some threshold. // This value can't be less than the ActivationWidth. var swipeThreshold = _TopCommandPanel.ActualHeight + ExtraSwipeThreshold; if (swipeThreshold < ActivationWidth) { swipeThreshold = ActivationWidth; } if (Math.Abs(newTranslationY) > swipeThreshold) { newTranslationY = swipeThreshold; } } // Don't allow swiping more than almost the whole content grid width // (doing this will cause the control to change size). if (newTranslationY > (_contentGrid.ActualHeight - 4)) { newTranslationY = _contentGrid.ActualHeight - 4; } } else { // Swiping from Bottom to Top if (!IsBottomCommandEnabled) { // If swipe is not enabled, only allow swipe a very short distance if (newTranslationY < 0) { swipingInDisabledArea = true; newSwipeStatus = SwipeStatus.DisabledSwipingToTop; } if (newTranslationY < -16) { newTranslationY = -16; } } else if (IsOffsetLimited) { // If offset is limited, there will be a limit how much swipe is possible. // This will be the value of the command panel plus some threshold. // This value can't be less than the ActivationWidth. var swipeThreshold = _BottomCommandPanel.ActualHeight + ExtraSwipeThreshold; if (swipeThreshold < ActivationWidth) { swipeThreshold = ActivationWidth; } if (Math.Abs(newTranslationY) > swipeThreshold) { newTranslationY = -swipeThreshold; } } // Don't allow swiping more than almost the whole content grid width // (doing this will cause the control to change size). if (newTranslationY < -(_contentGrid.ActualHeight - 4)) { newTranslationY = -(_contentGrid.ActualHeight - 4); } } bool hasPassedThreshold = !swipingInDisabledArea && Math.Abs(newTranslationY) >= ActivationWidth; if (swipingInDisabledArea) { // Don't show any command if swiping in disabled area. _commandContainer.Opacity = 0; _TopCommandPanel.Opacity = 0; _BottomCommandPanel.Opacity = 0; } else if (newTranslationY > 0) { // If swiping from Top to Bottom, show Top command panel. _BottomCommandPanel.Opacity = 0; _commandContainer.Background = TopBackground as SolidColorBrush; _commandContainer.Opacity = 1; _TopCommandPanel.Opacity = 1; _commandContainer.Clip.Rect = new Rect(0, 0, _commandContainer.ActualWidth, Math.Max(newTranslationY - 1, 0)); if (newTranslationY < ActivationWidth) { _TopCommandAnimationSet?.Stop(); _TopCommandPanel.RenderTransform = _TopCommandTransform; _TopCommandTransform.TranslateY = newTranslationY / 2; newSwipeStatus = SwipeStatus.SwipingToBottomThreshold; } else { if (SwipeStatus != SwipeStatus.SwipingPassedBottomThreshold) { // This will cover extrem cases when previous state wasn't // below threshold. _TopCommandAnimationSet?.Stop(); _TopCommandPanel.RenderTransform = _TopCommandTransform; _TopCommandTransform.TranslateY = SnappedCommandMargin; } newSwipeStatus = SwipeStatus.SwipingPassedBottomThreshold; } } else { // If swiping from Bottom to Top, show Bottom command panel. _TopCommandPanel.Opacity = 0; _commandContainer.Background = BottomBackground as SolidColorBrush; _commandContainer.Opacity = 1; _BottomCommandPanel.Opacity = 1; _commandContainer.Clip.Rect = new Rect(0, 0, _commandContainer.ActualWidth, _commandContainer.ActualHeight); Debug.WriteLine("Bottom: " + _commandContainer.Clip.Rect.Bottom); Debug.WriteLine("Top: " + _commandContainer.Clip.Rect.Top); if (-newTranslationY < ActivationWidth) { _BottomCommandAnimationSet?.Stop(); _BottomCommandPanel.RenderTransform = _BottomCommandTransform; _BottomCommandTransform.TranslateY = newTranslationY / 2; newSwipeStatus = SwipeStatus.SwipingToTopThreshold; } else { if (SwipeStatus != SwipeStatus.SwipingPassedTopThreshold) { // This will cover extrem cases when previous state wasn't // below threshold. _BottomCommandAnimationSet?.Stop(); _BottomCommandPanel.RenderTransform = _BottomCommandTransform; _BottomCommandTransform.TranslateY = -SnappedCommandMargin; } newSwipeStatus = SwipeStatus.SwipingPassedTopThreshold; } } _transform.TranslateY = newTranslationY; SwipeStatus = newSwipeStatus; }