public static RemoveItem ( |
||
itemsControl | ||
removeIndex | int | |
리턴 | void |
private void DragStarted(ItemsControl itemsControl) { Type dataType = _data.GetType(); if (!(dataType.IsSubclassOf(ItemType) || dataType == ItemType || ItemType.IsAssignableFrom(dataType))) { return; } UIElement draggedItemContainer = Helper.GetItemContainerFromPoint(itemsControl, _dragStartPosition); _isDragging = true; DataObject dObject = new DataObject(ItemType, _data); DragDropEffects e = System.Windows.DragDrop.DoDragDrop(itemsControl, dObject, DragDropEffects.Copy | DragDropEffects.Move); if ((e & DragDropEffects.Move) != 0) { if (draggedItemContainer != null) { int dragItemIndex = itemsControl.ItemContainerGenerator.IndexFromContainer(draggedItemContainer); Helper.RemoveItem(itemsControl, dragItemIndex); } else { Helper.RemoveItem(itemsControl, _data); } } ResetState(); }
void itemsControl_PreviewDrop(object sender, DragEventArgs e) { ItemsControl itemsControl = (ItemsControl)sender; DetachAdorners(); e.Handled = true; if (e.Data.GetDataPresent(ItemType)) { object itemToAdd = e.Data.GetData(ItemType); if ((e.KeyStates & DragDropKeyStates.ControlKey) != 0 && Helper.DoesItemExists(itemsControl, itemToAdd)) { if (MessageBox.Show("Item already exists. Do you want to overwrite it?", "Copy File", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Helper.RemoveItem(itemsControl, itemToAdd); } else { e.Effects = DragDropEffects.None; return; } } e.Effects = ((e.KeyStates & DragDropKeyStates.ControlKey) != 0) ? DragDropEffects.Copy : DragDropEffects.Move; Helper.AddItem(itemsControl, itemToAdd, FindInsertionIndex(itemsControl, e)); } else { e.Effects = DragDropEffects.None; } }