private static void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { var draggeditem = DataGridHelper.GetDraggedItem(sender as DependencyObject); if (draggeditem == null) { return; } ExchangeItems(sender, (sender as DataGrid).SelectedItem); (sender as DataGrid).SelectedItem = draggeditem; DataGridHelper.SetDraggedItem(sender as DataGrid, null); }
private static void OnMouseMove(object sender, MouseEventArgs e) { var draggeditem = DataGridHelper.GetDraggedItem(sender as DependencyObject); if (draggeditem == null) { return; } var row = TryFindFromPoint <DataGridRow>((UIElement)sender, e.GetPosition((sender as DataGrid))); if (row == null || row.IsEditing) { return; } ExchangeItems(sender, row.Item); }
private static void ExchangeItems(object sender, object targetItem) { var draggeditem = DataGridHelper.GetDraggedItem(sender as DependencyObject); if (draggeditem == null) { return; } if (targetItem != null && !ReferenceEquals(draggeditem, targetItem)) { var list = (sender as DataGrid).ItemsSource as IList; var targetIndex = list.IndexOf(targetItem); list.Remove(draggeditem); list.Insert(targetIndex, draggeditem); } }