예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }