Пример #1
0
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool canDrop = false;

            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell == null)
            {
                return(false);
            }

            ColumnReorderingDragSourceManager manager =
                draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                ColumnManagerCell cell = draggedElement as ColumnManagerCell;

                if ((cell != null) &&
                    (cell.IsBeingDragged))
                {
                    DataGridContext rowDataGridContext = DataGridControl.GetDataGridContext(this);

                    if ((rowDataGridContext != null) &&
                        (rowDataGridContext.Columns.Contains(cell.ParentColumn)))
                    {
                        canDrop = true;
                    }
                }
            }

            return(canDrop);
        }
        internal void ProcessDrop(ColumnManagerCell draggedCell)
        {
            ColumnReorderingDragSourceManager manager = null;

            if (draggedCell != null)
            {
                manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;
            }

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
            else
            {
                int oldPosition = draggedCell.ParentColumn.VisiblePosition;
                int newPosition = this.ParentColumn.VisiblePosition;

                if (m_dropMarkAdorner != null)
                {
                    DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;

                    this.HideDropMark();

                    if (draggedCell.ParentColumn.VisiblePosition < newPosition)
                    {
                        if (alignment == DropMarkAlignment.Near)
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition - 1;
                        }
                        else
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition;
                        }
                    }
                    else
                    {
                        if (alignment == DropMarkAlignment.Near)
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition;
                        }
                        else
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition + 1;
                        }
                    }

                    // This will force every Rows to update there layout
                    ColumnReorderingEventArgs e = new ColumnReorderingEventArgs(ColumnManagerCell.ColumnReorderingEvent, oldPosition, newPosition);
                    this.RaiseEvent(e);
                }
            }
        }
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell == null)
            {
                return;
            }

            ColumnReorderingDragSourceManager manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
        }
        void IDropTarget.DragLeave(UIElement draggedElement)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell != null)
            {
                ColumnReorderingDragSourceManager manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

                // No need for drop mark when performing animated Column reordering
                if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
                {
                    return;
                }
            }

            this.HideDropMark();
        }
        void IDropTarget.DragOver(UIElement draggedElement, Point mousePosition)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell != null)
            {
                ColumnReorderingDragSourceManager manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

                // No need for drop mark when performing animated Column reordering
                if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
                {
                    return;
                }
            }

            this.ShowDropMark(mousePosition);
        }
Пример #6
0
 internal static void SetColumnReorderingDragSourceManager(DependencyObject obj, ColumnReorderingDragSourceManager value)
 {
     obj.SetValue(TableflowView.ColumnReorderingDragSourceManagerProperty, value);
 }
Пример #7
0
        private void SetupDragManager()
        {
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            // We do not support DragDrop when there are no AdornerLayer because there wouldn't
            // be any visual feedback for the operation.
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);

            if (adornerLayer == null)
            {
                // When virtualizing, the Cell is not yet in the VisualTree because it is
                // the ParentRow's CellsHost which is reponsible of putting them in the
                // VisualTree. We try to get the adorner from the ParentRow instead
                if (this.ParentRow != null)
                {
                    adornerLayer = AdornerLayer.GetAdornerLayer(this.ParentRow);
                }

                if (adornerLayer == null)
                {
                    return;
                }
            }

            // Can be null in design-time (edition of a style TargetType ColumnManagerCell).
            if (dataGridContext == null)
            {
                return;
            }

            DataGridControl dataGridControl = dataGridContext.DataGridControl;

            if (dataGridControl == null)
            {
                return;
            }


            if (m_dragSourceManager != null)
            {
                m_dragSourceManager.PropertyChanged -= this.DragSourceManager_PropertyChanged;
            }

            // The DataGridControl's AdornerDecoratorForDragAndDrop must be used for dragging in order to include the
            // RenderTransform the DataGridControl may performs. This AdornerDecorator is defined in the ControlTemplate
            // as PART_DragDropAdornerDecorator
            if ((dataGridControl.DragDropAdornerDecorator != null) &&
                (dataGridControl.DragDropAdornerDecorator.AdornerLayer != null))
            {
                m_dragSourceManager = new ColumnReorderingDragSourceManager(this,
                                                                            dataGridControl.DragDropAdornerDecorator.AdornerLayer,
                                                                            dataGridControl);
            }
            else
            {
                m_dragSourceManager = new ColumnReorderingDragSourceManager(this,
                                                                            null,
                                                                            dataGridControl);
            }

            m_dragSourceManager.PropertyChanged += this.DragSourceManager_PropertyChanged;

            // Create bindings to ViewProperties for AutoScroll Properties
            Binding binding = new Binding();

            binding.Path = new PropertyPath("(0).(1)",
                                            DataGridControl.DataGridContextProperty,
                                            TableView.AutoScrollIntervalProperty);

            binding.Mode   = BindingMode.OneWay;
            binding.Source = this;

            BindingOperations.SetBinding(m_dragSourceManager, DragSourceManager.AutoScrollIntervalProperty, binding);

            binding        = new Binding();
            binding.Path   = new PropertyPath("(0).(1)", DataGridControl.DataGridContextProperty, TableView.AutoScrollTresholdProperty);
            binding.Mode   = BindingMode.OneWay;
            binding.Source = this;

            BindingOperations.SetBinding(m_dragSourceManager, DragSourceManager.AutoScrollTresholdProperty, binding);
        }
        private void SetupDragManager()
        {
            // Prevent any drag operation if columns layout is changing.
            var dataGridContext = this.DataGridContext;

            if ((dataGridContext == null) || (dataGridContext.ColumnManager.IsUpdateDeferred))
            {
                return;
            }

            // We do not support DragDrop when there are no AdornerLayer because there wouldn't be any visual feedback for the operation.
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);

            if (adornerLayer == null)
            {
                // When virtualizing, the Cell is not yet in the VisualTree because it is the ParentRow's CellsHost which
                // is reponsible of putting them in the VisualTree. We try to get the adorner from the ParentRow instead
                if (this.ParentRow != null)
                {
                    adornerLayer = AdornerLayer.GetAdornerLayer(this.ParentRow);
                }

                if (adornerLayer == null)
                {
                    return;
                }
            }

            var dataGridControl = dataGridContext.DataGridControl;

            Debug.Assert(dataGridControl != null);

            if (m_dragSourceManager != null)
            {
                m_dragSourceManager.PropertyChanged -= this.DragSourceManager_PropertyChanged;
            }

            // The DataGridControl's AdornerDecoratorForDragAndDrop must be used for dragging in order to include the RenderTransform
            // the DataGridControl may performs. This AdornerDecorator is defined in the ControlTemplate as PART_DragDropAdornerDecorator
            if ((dataGridControl.DragDropAdornerDecorator != null) && (dataGridControl.DragDropAdornerDecorator.AdornerLayer != null))
            {
                m_dragSourceManager = new ColumnReorderingDragSourceManager(this, dataGridControl.DragDropAdornerDecorator.AdornerLayer, dataGridControl, this.ParentRow.LevelCache);
            }
            else
            {
                m_dragSourceManager = new ColumnReorderingDragSourceManager(this, null, dataGridControl, this.ParentRow.LevelCache);
            }

            m_dragSourceManager.PropertyChanged += this.DragSourceManager_PropertyChanged;

            // Create bindings to ViewProperties for AutoScroll Properties
            Binding binding = new Binding();

            binding.Path      = new PropertyPath("(0).(1)", DataGridControl.DataGridContextProperty, TableView.AutoScrollIntervalProperty);
            binding.Mode      = BindingMode.OneWay;
            binding.Source    = this;
            binding.Converter = new MillisecondsConverter();
            BindingOperations.SetBinding(m_dragSourceManager, DragSourceManager.AutoScrollIntervalProperty, binding);

            binding        = new Binding();
            binding.Path   = new PropertyPath("(0).(1)", DataGridControl.DataGridContextProperty, TableView.AutoScrollThresholdProperty);
            binding.Mode   = BindingMode.OneWay;
            binding.Source = this;
            BindingOperations.SetBinding(m_dragSourceManager, DragSourceManager.AutoScrollThresholdProperty, binding);
        }