Esempio n. 1
0
        private static void ExchangeRows(object sender, object target)
        {
            var draggedRow = RowDragHelper.GetDraggedItem(sender as DependencyObject);

            if (draggedRow == null)
            {
                return;
            }

            if (target != null && !ReferenceEquals(draggedRow, target))
            {
                var list = ((DataGrid)sender).ItemsSource as IList;
                if (list == null)
                {
                    return;
                }

                int oldIndex = list.IndexOf(draggedRow);

                var targetIndex = list.IndexOf(target);
                list.Remove(draggedRow);
                list.Insert(targetIndex, draggedRow);

                //Console.WriteLine("Row Switch");

                RowSwitchEventArgs args = new RowSwitchEventArgs()
                {
                    PrimaryRowIndex   = targetIndex,
                    DisplacedRowIndex = oldIndex
                };

                OnRowSwitch(args);
            }
        }
Esempio n. 2
0
        private static void RowDragOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            var draggedItem = RowDragHelper.GetDraggedItem(sender as DependencyObject);

            if (draggedItem == null)
            {
                return;
            }

            //disabled because it seems to glitch out when 2 custom programs are swapped
            //ExchangeRows(sender, ((DataGrid) sender).SelectedItem);

            ((DataGrid)sender).SelectedItem = draggedItem;
            RowDragHelper.SetDraggedItem(sender as DataGrid, null);
        }
Esempio n. 3
0
        private static void RowDragOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            var      draggedRow = RowDragHelper.GetDraggedItem(sender as DependencyObject);
            DataGrid g          = sender as DataGrid;

            if (draggedRow == null || g == null)
            {
                return;
            }

            var targetRow = GetRowFromPoint(g, mouseEventArgs.GetPosition(g));

            if (targetRow == null)
            {
                return;
            }

            ExchangeRows(g, targetRow.Item);
        }