/// <summary> /// Handles the PreviewMouseMove event of the ReorderableListBox control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param> private void OnPreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { if (this.overlayElement != null) { this.dragging = true; Point currentPosition = (Point)e.GetPosition((IInputElement)this); this.overlayElement.LeftOffset = currentPosition.X; this.overlayElement.TopOffset = currentPosition.Y; } else { if (this.SelectedIndex != -1) { this.dragging = true; this.originalItemIndex = this.SelectedIndex; ListBoxItem listBoxItem = (ListBoxItem)ItemContainerGenerator.ContainerFromIndex(this.originalItemIndex); this.overlayElement = new DropPreviewAdorner((UIElement)this, listBoxItem); this.AdornerLayer.Add(this.overlayElement); } } } }
/// <summary> /// Handles the PreviewMouseLeftButtonUp event of the ReorderableListBox control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param> private void OnPreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (this.dragging == true) { this.dragging = false; this.adornerLayer.Remove(this.overlayElement); this.overlayElement = null; object originalItem = this.Items[this.originalItemIndex]; RoutedEventArgs routedEventArgs = new RoutedEventArgs(ItemsReorderedEvent, this); this.RaiseEvent(routedEventArgs); } }