private void DragDropDown(object sender, MouseButtonEventArgs e) { this.sourceBox = (ListBox)sender; Visual visual = e.OriginalSource as Visual; this.topWindow = Window.GetWindow(this.sourceBox); this.startPoint = e.GetPosition(this.topWindow); this.sourceItem = sourceBox.ContainerFromElement(visual) as ListBoxItem; if (this.sourceItem != null) { this.draggedData = (int)this.sourceItem.DataContext; } }
// Check if Drag & Drop is initiated private void ListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Handle Doubleclick if (e.ClickCount > 1) return; // Remember DragStartPosition dragSource = (ListBox) sender; dragStartPoint = e.GetPosition(dragSource); // if this element is selected, supress click to allow multiple selections var listItem = dragSource.ContainerFromElement((Visual) e.OriginalSource) as FrameworkElement; if (listItem == null) return; currentClickedSchüler = dragSource.ItemContainerGenerator.ItemFromContainer(listItem) as Schueler; if (dragSource.SelectedItems.Contains(currentClickedSchüler)) { // Prevent further handling to allow Drag and Drop of multi-selections // Remember to handle it later with DragMoveStarted flag e.Handled = true; DragMoveStarted = true; } }