private static Point GetRearrangePosition(IReorderItem targetItem, IReorderItem adjacentItem)
        {
            var position         = targetItem.ArrangePosition;
            var dragPositionMode = DragDrop.GetDragPositionMode(targetItem.Visual);

            if (dragPositionMode == DragPositionMode.RailY || dragPositionMode == DragPositionMode.Free)
            {
                position.Y = adjacentItem.ArrangePosition.Y;

                if (targetItem.LogicalIndex < adjacentItem.LogicalIndex)
                {
                    position.Y += adjacentItem.ActualSize.Height - targetItem.ActualSize.Height;
                }
            }

            if (dragPositionMode == DragPositionMode.RailX || dragPositionMode == DragPositionMode.Free)
            {
                position.X = adjacentItem.ArrangePosition.X;

                if (targetItem.LogicalIndex < adjacentItem.LogicalIndex)
                {
                    position.X += adjacentItem.ActualSize.Width - targetItem.ActualSize.Width;
                }
            }

            return(position);
        }
예제 #2
0
        private void PrepareActionContent()
        {
            DragPositionMode dragMode = DragDrop.GetDragPositionMode(this);
            ContentControl   swipeActionContentControl = this.ListView.swipeActionContentControl;

            swipeActionContentControl.DataContext = this.DataContext;

            if (dragMode.HasFlag(DragPositionMode.RailXForward) || dragMode.HasFlag(DragPositionMode.RailXBackwards))
            {
                swipeActionContentControl.Width  = this.ActualWidth;
                swipeActionContentControl.Height = this.ActualHeight;

                Canvas.SetLeft(swipeActionContentControl, 0);
                Canvas.SetTop(swipeActionContentControl, Canvas.GetTop(this));
            }
            else
            {
                swipeActionContentControl.Width  = this.ActualWidth;
                swipeActionContentControl.Height = this.ActualHeight;

                Canvas.SetLeft(swipeActionContentControl, Canvas.GetLeft(this));
                Canvas.SetTop(swipeActionContentControl, 0);
            }

            swipeActionContentControl.Margin = this.Margin;

            swipeActionContentControl.Visibility = Visibility.Visible;

            swipeActionContentControl.Tapped += this.SwipeActionContentControl_Tapped;

            this.ListView.isActionContentDisplayed = true;
        }
예제 #3
0
        private static Point GetRearangePosition(IReorderItem targetItem, IReorderItem adjasentItem)
        {
            Point position;

            if (targetItem.LogicalIndex > adjasentItem.LogicalIndex)
            {
                position = adjasentItem.ArrangePosition;
            }
            else
            {
                double x = -1;
                double y = -1;
                var    dragPositionMode = DragDrop.GetDragPositionMode(targetItem.Visual);

                if (dragPositionMode == DragPositionMode.RailY || dragPositionMode == DragPositionMode.Free)
                {
                    x = adjasentItem.ArrangePosition.X;
                    y = adjasentItem.ArrangePosition.Y + adjasentItem.ActualSize.Height - targetItem.ActualSize.Height;
                }

                if (dragPositionMode == DragPositionMode.RailX || dragPositionMode == DragPositionMode.Free)
                {
                    x = adjasentItem.ArrangePosition.X + adjasentItem.ActualSize.Width - targetItem.ActualSize.Width;
                    y = adjasentItem.ArrangePosition.Y;
                }
                position = new Point(x, y);
            }

            return(position);
        }
예제 #4
0
        internal void OnDragComplete(ItemSwipeActionCompleteContext context)
        {
            var dragPos = DragDrop.GetDragPositionMode(this);

            if (dragPos.HasFlag(DragPositionMode.RailXForward) || dragPos.HasFlag(DragPositionMode.RailXBackwards))
            {
                Canvas.SetLeft(this, context.FinalDragOffset);
            }
            else
            {
                Canvas.SetTop(this, context.FinalDragOffset);
            }
        }
        protected void AnimateItem(IReorderItem source, IReorderItem destination, Point position)
        {
            var dragPositionMode = DragDrop.GetDragPositionMode(destination.Visual);

            Storyboard b = new Storyboard();
            Action     actionCompleted = () =>
            {
                destination.ArrangePosition = position;
                this.animatingElements.Remove(destination);
                this.Host.OnItemsReordered(source, destination);
            };

            this.runningAnimations.Add(b, actionCompleted);

            if (dragPositionMode == DragPositionMode.RailY || dragPositionMode == DragPositionMode.Free)
            {
                var topAnimation = new DoubleAnimation();
                topAnimation.Duration       = DefaultAnimationDuration;
                topAnimation.EasingFunction = new QuadraticEase()
                {
                    EasingMode = EasingMode.EaseIn
                };
                topAnimation.To = position.Y;
                Storyboard.SetTargetProperty(topAnimation, "(Canvas.Top)");
                Storyboard.SetTarget(topAnimation, destination.Visual);
                b.Children.Add(topAnimation);
            }

            if (dragPositionMode == DragPositionMode.RailX || dragPositionMode == DragPositionMode.Free)
            {
                var leftAnimation = new DoubleAnimation();
                leftAnimation.Duration       = DefaultAnimationDuration;
                leftAnimation.EasingFunction = new QuadraticEase()
                {
                    EasingMode = EasingMode.EaseIn
                };
                leftAnimation.To = position.X;
                Storyboard.SetTargetProperty(leftAnimation, "(Canvas.Left)");
                Storyboard.SetTarget(leftAnimation, destination.Visual);
                b.Children.Add(leftAnimation);
            }

            b.Completed += (s, e) =>
            {
                runningAnimations.Remove(b);
                actionCompleted();
            };

            b.Begin();
        }
예제 #6
0
        protected virtual void AnimateItem(IReorderItem item, Point position, Action actionCompleted)
        {
            var dragPositionMode = DragDrop.GetDragPositionMode(item.Visual);

            Storyboard b = new Storyboard();

            this.runningAnimations.Add(b, actionCompleted);

            if (dragPositionMode == DragPositionMode.RailY || dragPositionMode == DragPositionMode.Free)
            {
                var topAnimation = new DoubleAnimation();
                topAnimation.Duration       = DefaultAnimationDuration;
                topAnimation.EasingFunction = new QuadraticEase()
                {
                    EasingMode = EasingMode.EaseIn
                };
                topAnimation.To = position.Y;
                Storyboard.SetTargetProperty(topAnimation, "(Canvas.Top)");
                Storyboard.SetTarget(topAnimation, item.Visual);
                b.Children.Add(topAnimation);
            }

            if (dragPositionMode == DragPositionMode.RailX || dragPositionMode == DragPositionMode.Free)
            {
                var leftAnimation = new DoubleAnimation();
                leftAnimation.Duration       = DefaultAnimationDuration;
                leftAnimation.EasingFunction = new QuadraticEase()
                {
                    EasingMode = EasingMode.EaseIn
                };
                leftAnimation.To = position.X;
                Storyboard.SetTargetProperty(leftAnimation, "(Canvas.Left)");
                Storyboard.SetTarget(leftAnimation, item.Visual);
                b.Children.Add(leftAnimation);
            }

            b.Completed += (s, e) =>
            {
                runningAnimations.Remove(b);
                actionCompleted();
            };

            b.Begin();
        }
예제 #7
0
        void IDragDropElement.OnDragDropComplete(DragCompleteContext context)
        {
            var data = context.PayloadData as ReorderItemsDragOperation;

            if (data != null)
            {
                this.FinalizeReorder(context);

                object destinationDataItem = this.GetDestinationDataItem(data);
                bool   isExecuted          = this.ListView.commandService.ExecuteCommand(CommandId.ItemReorderComplete, new ItemReorderCompleteContext(data.Data, destinationDataItem, this));
            }
            else
            {
                if (context.DragSuccessful)
                {
                    double offset   = 0;
                    var    dragMode = DragDrop.GetDragPositionMode(this);

                    if (this.ListView.Orientation == Orientation.Horizontal)
                    {
                        switch (dragMode)
                        {
                        case DragPositionMode.RailXForward:
                            offset = Math.Max(0, this.dragY);
                            break;

                        case DragPositionMode.RailXBackwards:
                            offset = Math.Min(0, dragY);
                            break;

                        case DragPositionMode.RailX:
                            offset = this.dragY;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        switch (dragMode)
                        {
                        case DragPositionMode.RailXForward:
                            offset = Math.Max(0, this.dragX);
                            break;

                        case DragPositionMode.RailXBackwards:
                            offset = Math.Min(0, dragX);
                            break;

                        case DragPositionMode.RailX:
                            offset = this.dragX;
                            break;

                        default:
                            break;
                        }
                    }
                    var swipeContext = new ItemSwipeActionCompleteContext(this.DataContext, this, offset);

                    bool isExecuted = this.ListView.commandService.ExecuteCommand(CommandId.ItemSwipeActionComplete, swipeContext);

                    if (isExecuted)
                    {
                        this.UpdateActionContentClipping(swipeContext.FinalDragOffset);
                        this.isDraggedForAction  = true;
                        this.ListView.swipedItem = this;
                    }
                    else
                    {
                        this.ClearActionContent();
                    }
                }
                else
                {
                    this.ClearActionContent();
                    this.ListView.CleanupSwipedItem();
                }
            }
            this.Opacity = 1;

            DragDrop.SetDragPositionMode(this, DragPositionMode.Free);
            this.ListView.InvalidatePanelArrange();
        }
        void IDragDropElement.OnDragDropComplete(DragCompleteContext context)
        {
            var data = context.PayloadData as ReorderItemsDragOperation;

            if (data != null)
            {
                this.FinalizeReorder(context);

                var                  isExecuted      = false;
                RadListViewItem      destinationItem = null;
                ItemReorderPlacement placement       = 0;

                if (data.InitialSourceIndex < data.CurrentSourceReorderIndex)
                {
                    destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex - 1) as RadListViewItem;
                    placement       = ItemReorderPlacement.After;

                    if (destinationItem == null)
                    {
                        destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex + 1) as RadListViewItem;
                        placement       = ItemReorderPlacement.Before;
                    }
                }
                else if (data.InitialSourceIndex > data.CurrentSourceReorderIndex)
                {
                    destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex + 1) as RadListViewItem;
                    placement       = ItemReorderPlacement.Before;

                    if (destinationItem == null)
                    {
                        destinationItem = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex - 1) as RadListViewItem;
                        placement       = ItemReorderPlacement.After;
                    }
                }

                if (destinationItem != null)
                {
                    var dataItem            = data.Data;
                    var destinationDataItem = destinationItem.DataContext;

                    IDataGroup dataGroup            = null;
                    IDataGroup destinationDataGroup = null;

                    if (this.listView.GroupDescriptors.Count > 0)
                    {
                        dataGroup            = this.listView.Model.FindItemParentGroup(dataItem);
                        destinationDataGroup = this.listView.Model.FindItemParentGroup(destinationDataItem);
                    }

                    var commandContext = new ItemReorderCompleteContext(dataItem, dataGroup, destinationDataItem, destinationDataGroup, placement);

                    isExecuted = this.ListView.commandService.ExecuteCommand(CommandId.ItemReorderComplete, commandContext);
                }

                if (isExecuted)
                {
                    // TODO: Data provider does not handle well reordering of items in groups.
                    // Remove this workaround once we fix the reordering in the data provider.
                    if (this.listView.GroupDescriptors.Count > 0)
                    {
                        this.listView.updateService.RegisterUpdate((int)UpdateFlags.AffectsData);
                    }
                }
                else
                {
                    this.reorderCoordinator.CancelReorderOperation(this, data.InitialSourceIndex);
                }
            }
            else
            {
                if (context.DragSuccessful)
                {
                    double offset   = 0;
                    var    dragMode = DragDrop.GetDragPositionMode(this);

                    if (this.ListView.Orientation == Orientation.Horizontal)
                    {
                        switch (dragMode)
                        {
                        case DragPositionMode.RailXForward:
                            offset = Math.Max(0, this.dragY);
                            break;

                        case DragPositionMode.RailXBackwards:
                            offset = Math.Min(0, this.dragY);
                            break;

                        case DragPositionMode.RailX:
                            offset = this.dragY;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        switch (dragMode)
                        {
                        case DragPositionMode.RailXForward:
                            offset = Math.Max(0, this.dragX);
                            break;

                        case DragPositionMode.RailXBackwards:
                            offset = Math.Min(0, this.dragX);
                            break;

                        case DragPositionMode.RailX:
                            offset = this.dragX;
                            break;

                        default:
                            break;
                        }
                    }
                    var swipeContext = new ItemSwipeActionCompleteContext(this.DataContext, this, offset);

                    bool isExecuted = this.ListView.commandService.ExecuteCommand(CommandId.ItemSwipeActionComplete, swipeContext);

                    if (isExecuted)
                    {
                        this.UpdateActionContentClipping(swipeContext.FinalDragOffset);
                        this.isDraggedForAction  = true;
                        this.ListView.swipedItem = this;
                    }
                    else
                    {
                        this.ClearActionContent();
                    }
                }
                else
                {
                    this.ClearActionContent();
                    this.ListView.CleanupSwipedItem();
                }
            }
            this.Opacity = 1;

            DragDrop.SetDragPositionMode(this, DragPositionMode.Free);
            this.ListView.InvalidatePanelArrange();
        }
예제 #9
0
        private void UpdateActionContentClipping(double offset)
        {
            double x      = 0;
            double y      = 0;
            double width  = this.ListView.swipeActionContentControl.ActualWidth;
            double height = this.ListView.swipeActionContentControl.ActualHeight;

            var dragMode = DragDrop.GetDragPositionMode(this);

            if (offset > 0)
            {
                if (this.ListView.Orientation == Windows.UI.Xaml.Controls.Orientation.Horizontal)
                {
                    if (dragMode.HasFlag(DragPositionMode.RailYForward))
                    {
                        height = Math.Max(offset, 0);
                    }
                    else
                    {
                        height = 0;
                    }
                }
                else
                {
                    if (dragMode.HasFlag(DragPositionMode.RailXForward))
                    {
                        width = Math.Max(offset, 0);
                    }
                    else
                    {
                        width = 0;
                    }
                }
            }
            else
            {
                if (this.ListView.Orientation == Windows.UI.Xaml.Controls.Orientation.Horizontal)
                {
                    if (dragMode.HasFlag(DragPositionMode.RailYBackwards))
                    {
                        y = Math.Max(0, height + offset);
                    }
                    else
                    {
                        y = height;
                    }
                }
                else
                {
                    if (dragMode.HasFlag(DragPositionMode.RailXBackwards))
                    {
                        x = Math.Max(0, width + offset);
                    }
                    else
                    {
                        x = width;
                    }
                }
            }

            this.ListView.swipeActionContentControl.Clip = new Windows.UI.Xaml.Media.RectangleGeometry()
            {
                Rect = new Rect(x, y, width, height)
            };
        }