public void OnDragEnd() { if (DragEnd != null) { DragEnd(DragDropService.ActiveItem); } DragDropService.Reset(); //dragTargetItem = default; }
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(); }
public override void OnDrop() { var activeItem = DragDropService.ActiveItem; DragDropService.ShouldRender = true; if (_dropzone.IsItemAccepted() == false) { _dropzone.OnItemDropRejected.InvokeAsync(activeItem); DragDropService.Reset(); return; } if (_dropzone.dragTargetItem == null) //no direct drag target { if (_dropzone.CopyItem == null) { _dropzone.Items.Add(activeItem); //insert item to new zone DragDropService.Items.Remove(activeItem); //remove from old zone } else { _dropzone.Items.Add(_dropzone.CopyItem(activeItem)); //insert item to new zone } } else // we have a direct target { if (_dropzone.InstantReplace == false) { _dropzone.Swap(_dropzone.dragTargetItem, activeItem); //swap target with active item } } _dropzone.dragTargetItem = default(TItem); _dropzone.StateHasChanged(); _dropzone.OnItemDrop.InvokeAsync(activeItem); }
protected void _defaultOnDragEnd() { DragDropService.Reset(); GroupService.UnsetSelectedGroup(); }
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(); }