Beispiel #1
0
        private void OnDropItemOnSpacing(int newIndex)
        {
            if (!IsDropAllowed())
            {
                DragDropService.Reset();
                return;
            }

            var activeItem   = DragDropService.ActiveItem;
            var oldIndex     = Items.IndexOf(activeItem);
            var sameDropZone = false;

            if (oldIndex == -1) // item not present in target dropzone
            {
                if (CopyItem == null)
                {
                    if (DragDropService.Items != null)
                    {
                        DragDropService.Items.Remove(activeItem);
                    }
                }
            }
            else // same dropzone drop
            {
                sameDropZone = true;
                Items.RemoveAt(oldIndex);
                // the actual index could have shifted due to the removal
                if (newIndex > oldIndex)
                {
                    newIndex--;
                }
            }

            if (CopyItem == null)
            {
                Items.Insert(newIndex, activeItem);
            }
            else
            {
                // for the same zone - do not call CopyItem
                Items.Insert(newIndex, sameDropZone ? activeItem : CopyItem(activeItem));
            }

            OnItemDrop.InvokeAsync(activeItem);

            //Operation is finished
            DragDropService.Reset();
        }
Beispiel #2
0
        private void OnDrop()
        {
            if (!IsDropAllowed())
            {
                this.Reset();
                return;
            }

            var activeItem = this.ActiveItem;

            if (this.DragTargetItem == null)     //no direct drag target
            {
                if (!Items.Contains(activeItem)) //if dragged to another dropzone
                {
                    if (CopyItem == null)
                    {
                        Items.Insert(Items.Count, activeItem); //insert item to new zone
                        this.Items.Remove(activeItem);         //remove from old zone
                    }
                    else
                    {
                        Items.Insert(Items.Count, CopyItem(activeItem)); //insert item to new zone
                    }
                }
                else
                {
                    //what to do here?
                }
            }
            else // we have a direct target
            {
                if (!InstantReplace)
                {
                    Swap(this.DragTargetItem, activeItem); //swap target with active item
                    OnItemDroped?.Invoke(this.ActiveItem, this.DragTargetItem);
                }
            }

            this.Reset();
            StateHasChanged();
            OnItemDrop.InvokeAsync(activeItem);
        }
Beispiel #3
0
        private void OnDropItemOnSpacing(int newIndex)
        {
            if (!IsDropAllowed())
            {
                this.Reset();
                return;
            }

            var activeItem = this.ActiveItem;
            var oldIndex   = Items.IndexOf(activeItem);

            if (oldIndex == -1) // item not present in target dropzone
            {
                if (CopyItem == null)
                {
                    this.Items.Remove(activeItem);
                }
            }
            else // same dropzone drop
            {
                Items.RemoveAt(oldIndex);
                // the actual index could have shifted due to the removal
                if (newIndex > oldIndex)
                {
                    newIndex--;
                }
            }

            if (CopyItem == null)
            {
                Items.Insert(newIndex, activeItem);
            }
            else
            {
                Items.Insert(newIndex, CopyItem(activeItem));
            }

            //Operation is finished
            this.Reset();
            OnItemDrop.InvokeAsync(activeItem);
        }
Beispiel #4
0
        private void OnDrop()
        {
            DragDropService.ShouldRender = true;
            if (!IsDropAllowed())
            {
                DragDropService.Reset();
                return;
            }

            var activeItem = DragDropService.ActiveItem;

            if (DragDropService.DragTargetItem == null) //no direct drag target
            {
                if (!Items.Contains(activeItem))        //if dragged to another dropzone
                {
                    if (CopyItem == null)
                    {
                        Items.Insert(Items.Count, activeItem); //insert item to new zone
                        if (DragDropService.Items != null)
                        {
                            DragDropService.Items.Remove(activeItem); //remove from old zone
                        }
                    }
                    else
                    {
                        Items.Insert(Items.Count, CopyItem(activeItem)); //insert item to new zone
                    }
                }
                else
                {
                    //what to do here?
                }
            }
            else // we have a direct target
            {
                if (!Items.Contains(activeItem)) // if dragged to another dropzone
                {
                    if (CopyItem == null)
                    {
                        if (!InstantReplace)
                        {
                            Swap(DragDropService.DragTargetItem, activeItem); //swap target with active item
                        }
                    }
                    else
                    {
                        if (!InstantReplace)
                        {
                            Swap(DragDropService.DragTargetItem, CopyItem(activeItem)); //swap target with a copy of active item
                        }
                    }
                }
                else
                {
                    // if dragged to the same dropzone
                    if (!InstantReplace)
                    {
                        Swap(DragDropService.DragTargetItem, activeItem); //swap target with active item
                    }
                }
            }

            OnItemDrop.InvokeAsync(activeItem);

            DragDropService.Reset();
            StateHasChanged();
        }