Exemplo n.º 1
0
        private void DataGrid_CellDrop(object sender, DragEventArgs e)
        {
            DataGridCell dgc = sender as DataGridCell;

            if (_draggedData != null && !_isMultipleCells)
            {
                MappedValue selectedCell = _draggedData as MappedValue;

                RowViewModel     sourceRowModel    = (selectedCell.RowBinding as RowViewModel);
                ColumnsViewModel sourceColumnModel = (selectedCell.ColumnBinding as ColumnsViewModel);


                RowViewModel     targetRowModel    = ((BindableColumn.ViewModel.RowViewModel)(dgc.DataContext));
                ColumnsViewModel targetColumnModel = ((BindableColumn.ViewModel.ColumnsViewModel)((dgc.Column).Header));

                targetCell = targetRowModel.Name + targetColumnModel.Currency;
                sourceCell = sourceRowModel.Name + sourceColumnModel.Currency;


                if (sourceCell == targetCell)
                {
                    RemoveDraggedAdorner();
                    RemoveInsertionAdorner();
                    (this._sourceItemsControl as DataGrid).UnselectAllCells();
                    dgc.IsSelected = false;
                    return;
                }

                MappedValueCollection mappedValueCollection = this._mappedValueCollection;
                var movingCellData = mappedValueCollection.ReturnIfExistAddIfNot(sourceColumnModel, sourceRowModel);

                if (mappedValueCollection.AddCellValue(targetRowModel, targetColumnModel, movingCellData))
                {
                    if (movingCellData.Value != null)
                    {
                        dgc.IsSelected = true;
                    }

                    mappedValueCollection.EmptyCellValue(sourceRowModel, sourceColumnModel);
                }
            }
            else if (_draggedData != null && _isMultipleCells)
            {
                RowViewModel     targetRowModel    = ((BindableColumn.ViewModel.RowViewModel)(dgc.DataContext));
                ColumnsViewModel targetColumnModel = ((BindableColumn.ViewModel.ColumnsViewModel)((dgc.Column).Header));

                targetCell = targetRowModel.Name + targetColumnModel.Currency;

                if (MoveMultipleCells(targetCell, this._multipleDraggedData.Count))
                {
                    this._multipleDraggedData.Clear();
                }
            }

            RemoveDraggedAdorner();
            RemoveInsertionAdorner();
            this._multipleDraggedData.Clear();
            (this._sourceItemsControl as DataGrid).UnselectAllCells();
        }