private void Element_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { Debug.WriteLine("ManipulationDelta"); if (!IsActive) { return; } // set the event to handled in order to avoid scrolling the ScrollViewer e.Handled = true; // move our 'drag image'. _dragImage.SetVerticalOffset(_dragImage.GetVerticalOffset().Value + e.DeltaManipulation.Translation.Y); }
private void HoldDelta(object sender, ManipulationDeltaEventArgs e) { if (!IsEnabled) { return; } if (!IsActive && !ShouldActivate(e)) { return; } e.Handled = true; if (!IsActive) { IsActive = true; var relativePosition = _cardView.GetRelativePositionIn(_itemsControl); PopoutCard(_cardView, _dragImage, relativePosition); _dispatcherTimer.Start(); } var dragTop = _dragImage.GetVerticalOffset().Value; var dragMid = _dragImage.ActualHeight / 2; var potentialY = dragTop + e.DeltaManipulation.Translation.Y; if (potentialY <= 0) { potentialY = 0; } var potentialIntersect = potentialY + dragMid + _scrollViewer.VerticalOffset; if (potentialIntersect <= 0) { potentialIntersect = 0; } var isDownward = e.DeltaManipulation.Translation.Y > 0; if (!isDownward && dragTop <= 0) { potentialIntersect = 0; } var potentialIndex = GetPotentialIndex(_currentIndex, potentialIntersect, isDownward); if (_currentIndex != potentialIndex) { // We only want to reindex if the index we've moved the card to // has changed, based on hardcore maths. _pointIndex.ShuffleItems(_currentIndex, potentialIndex); _currentIndex = potentialIndex; } // Move the drag image _dragImage.SetVerticalOffset(potentialY); }
private static void PopoutCard(UIElement element, DragImage image, Point relativePosition) { // Copy the selected card into a bitmap for use as the movement target var bitmap = new WriteableBitmap(element, null); image.Image.Source = bitmap; image.Visibility = Visibility.Visible; image.Opacity = 1.0; // this needs to be relative to the scrolled position image.SetVerticalOffset(relativePosition.Y); //image.SetHorizontalOffset(relativePosition.X); // hide the underlying item element.Opacity = 0.0; }