예제 #1
0
        private void Element_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            if (!IsActive)
            {
                return;
            }

            IsActive = false;
            _autoScrollTimer.Stop();

            int dragIndex = GetDragIndex();

            // fade in the list
            _todoList.Animate(null, 1.0, FrameworkElement.OpacityProperty, 200, 0);

            // animated the dragged item into location
            double targetLocation = dragIndex * _dragImage.ActualHeight - _scrollViewer.VerticalOffset;
            var    trans          = _dragImage.GetVerticalOffset().Transform;

            trans.Animate(null, targetLocation, TranslateTransform.YProperty, 200, 0, null,
                          () =>
            {
                // move the dragged item
                var draggedItem = _todoItems[_initialDragIndex];
                _todoItems.Remove(draggedItem);
                _todoItems.Insert(dragIndex, draggedItem);

                // re-populate our ObservableCollection
                RefreshView();

                // fade out the dragged image and collapse on completion
                _dragImage.Animate(null, 0.0, FrameworkElement.OpacityProperty, 1000, 0, null, ()
                                   => _dragImage.Visibility = Visibility.Collapsed);
            });
        }
예제 #2
0
        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);
        }
예제 #3
0
        private void Element_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            if (!IsActive)
            {
                return;
            }

            IsActive = false;
            _autoScrollTimer.Stop();

            int dragIndex = GetDragIndex();

            // fade in the list
            this.interactionListControl.Animate(null, 1.0, FrameworkElement.OpacityProperty, 200, 0);

            // animated the dragged item into location
            double targetLocation = dragIndex * _dragImage.ActualHeight - _scrollViewer.VerticalOffset;
            var    trans          = _dragImage.GetVerticalOffset().Transform;

            trans.Animate(null, targetLocation, TranslateTransform.YProperty, 200, 0, null,
                          () =>
            {
                // move the dragged item
                var draggedItem = this.interactionList[_initialDragIndex];
                this.itemManager.SetItemOrder(draggedItem, dragIndex == 0 ? null : this.interactionList[dragIndex - 1], dragIndex < this.interactionList.Count - 1 ? this.interactionList[dragIndex] : null, true);
                //this.interactionList.RemoveAt(_initialDragIndex);
                //this.interactionList.Add(draggedItem);

                // re-populate our ObservableCollection
                RefreshView();

                // fade out the dragged image and collapse on completion
                _dragImage.Animate(null, 0.0, FrameworkElement.OpacityProperty, 1000, 0, null, ()
                                   => _dragImage.Visibility = Visibility.Collapsed);
            });
        }