public void AcceptDrag(IDragableObject dragObject, Point position)
        {
            DragObject obj = dragObject as DragObject;

            if (obj == null)
            {
                return;
            }

            AgDataGridRow targetRow = GetRowAtPos(position);

            if (targetRow == null)
            {
                return;
            }

            CorrectRowsOrder();

            int targetSortOrder        = ((DataItem)targetRow.DataContext).SortOrder;
            int targetRowVisibleIndex  = dataGrid.GetRowVisibleIndex(targetRow.Handle);
            int draggedRowVisibleIndex = dataGrid.GetRowVisibleIndex(obj.Row.Handle);

            ((DataItem)obj.DataRow).SortOrder = targetSortOrder;

            //change rows order
            ChangeRowsOrder(targetRowVisibleIndex, draggedRowVisibleIndex);

            //resort grid data
            ResortGridData();
        }
        void OnNewDataRow(object sender, DataRowCreatedEventArgs e)
        {
            foreach (AgDataGridRow dataRow in dataRows)
            {
                dataRow.MouseLeftButtonDown -= new MouseButtonEventHandler(OnMouseLeftButtonDown);
            }
            dataRows.Clear();
            AgDataGridRow row = e.Row as AgDataGridRow;

            if (row != null)
            {
                row.MouseLeftButtonDown += new MouseButtonEventHandler(OnMouseLeftButtonDown);
            }
        }
示例#3
0
        public FrameworkElement CreateDragShape()
        {
            AgDataGridRow drag = new AgDataGridRow(this.row.Handle, this.source);

            drag.Opacity = .85;
            drag.Width   = this.row.ActualWidth;
            drag.Height  = this.row.ActualHeight;
            if (this.source.DataRowTemplate != null)
            {
                drag.Template = this.source.DataRowTemplate;
            }
            drag.ApplyTemplate();
            VisualStateManager.GoToState(drag, "Focused", true);
            return(drag);
        }
        protected virtual void StartDragging(AgDataGridRow row, Point point)
        {
            if (this.DataGrid == null)
            {
                return;
            }
            if (this.DragSurface == null)
            {
                return;
            }

            this.dragController = new DragControllerEx(
                DropContainer,
                new DragObject(row, DataGrid.GetDataRow(row.Handle), this.DataGrid),
                this.DragSurface,
                point,
                new Point(this.DataGrid.Margin.Left, this.DataGrid.Margin.Top));

            DragController.StartDragShift   = AgDataGrid.DefaultStartDragShift;
            DragController.ScrollOnDragging = null;
            this.DataGrid.CaptureMouse();
        }
 public DragObject(AgDataGridRow row, object dataRow, AgDataGrid source)
 {
     this.source  = source;
     this.row     = row;
     this.dataRow = dataRow;
 }