コード例 #1
0
        private void OnMouseMove_BeginReorder(Point mousePosition)
        {
            DataGridColumnHeader dragIndicator = new DataGridColumnHeader();

            dragIndicator.OwningColumn    = this.OwningColumn;
            dragIndicator.IsEnabled       = false;
            dragIndicator.Content         = this.Content;
            dragIndicator.ContentTemplate = this.ContentTemplate;

            Control dropLocationIndicator = new ContentControl();

            dropLocationIndicator.SetStyleWithType(this.OwningGrid.DropLocationIndicatorStyle);

            if (this.OwningColumn.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningColumn.DragIndicatorStyle);
            }
            else if (this.OwningGrid.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningGrid.DragIndicatorStyle);
            }

            // If the user didn't style the dragIndicator's Width, default it to the column header's width
            if (double.IsNaN(dragIndicator.Width))
            {
                dragIndicator.Width = this.ActualWidth;
            }

            // If the user didn't style the dropLocationIndicator's Height, default to the column header's height
            if (double.IsNaN(dropLocationIndicator.Height))
            {
                dropLocationIndicator.Height = this.ActualHeight;
            }

            // pass the caret's data template to the user for modification
            DataGridColumnReorderingEventArgs columnReorderingEventArgs = new DataGridColumnReorderingEventArgs(this.OwningColumn)
            {
                DropLocationIndicator = dropLocationIndicator,
                DragIndicator         = dragIndicator
            };

            this.OwningGrid.OnColumnReordering(columnReorderingEventArgs);
            if (columnReorderingEventArgs.Cancel)
            {
                return;
            }

            // The user didn't cancel, so prepare for the reorder
            _dragColumn = this.OwningColumn;
            _dragMode   = DragMode.Reorder;
            _dragStart  = mousePosition;

            // Display the reordering thumb
            this.OwningGrid.ColumnHeaders.DragColumn            = this.OwningColumn;
            this.OwningGrid.ColumnHeaders.DragIndicator         = columnReorderingEventArgs.DragIndicator;
            this.OwningGrid.ColumnHeaders.DropLocationIndicator = columnReorderingEventArgs.DropLocationIndicator;
        }
コード例 #2
0
        private void OnMouseMove_BeginReorder(Point mousePosition, Point mousePositionGridParent)
        {
            DataGridColumnHeader dragIndicator = new DataGridColumnHeader();
            dragIndicator.OwningColumn = this.OwningColumn;
            dragIndicator.IsEnabled = false;
            dragIndicator.Content = this.Content;
            dragIndicator.ContentTemplate = this.ContentTemplate;

            if (this.OwningColumn.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningColumn.DragIndicatorStyle);
            }
            else if (this.OwningGrid.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningGrid.DragIndicatorStyle);
            }

            // If the user didn't style the dragIndicator's Width, default it to the column header's width
            if (double.IsNaN(dragIndicator.Width))
            {
                dragIndicator.Width = this.ActualWidth;
            }

            // If the user didn't style the dropLocationIndicator's Height, default to the column header's height
            if (double.IsNaN(this.OwningGrid.ColumnDropLocationIndicator.Height))
            {
                this._autoSizeDropLocationIndicatorHeight = true;
                this.OwningGrid.ColumnDropLocationIndicator.Height = this.ActualHeight;
            }

            // pass the caret's data template to the user for modification
            DataGridColumnReorderingEventArgs columnReorderingEventArgs = new DataGridColumnReorderingEventArgs(this.OwningColumn)
            {
                DropLocationIndicator = this.OwningGrid.ColumnDropLocationIndicator,
                DragIndicator = dragIndicator
            };
            this.OwningGrid.OnColumnReordering(columnReorderingEventArgs);
            if (columnReorderingEventArgs.Cancel)
            {
                return;
            }

            // The user didn't cancel, so prepare for the reorder
            _dragColumn = this.OwningColumn;
            _dragMode = DragMode.Reorder;
            _dragStartParent = mousePositionGridParent;
            // the mouse position relative to the ColumnHeader needs to be scaled to be in the same
            // dimensions as the DataGrid, so that it doesn't get out of sync later on
            _dragStart = this.OwningGrid.RenderTransform.Transform(mousePosition);

            // Display the reordering thumb
            if (_reorderingThumb == null)
            {
                _reorderingThumb = new Popup();
            }

            _reorderingThumb.Child = columnReorderingEventArgs.DragIndicator;
            _reorderingThumb.IsOpen = true;

            // use the data template to populate the caret
            if (columnReorderingEventArgs.DropLocationIndicator != null)
            {
                System.Windows.Controls.Control child = columnReorderingEventArgs.DropLocationIndicator;

                this.OwningGrid.ColumnDropLocationIndicatorPopup.Child = child;
                this.OwningGrid.ColumnDropLocationIndicatorPopup.Height = child.ActualHeight;
                this.OwningGrid.ColumnDropLocationIndicatorPopup.Width = child.ActualWidth;

                this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = false;
            }
        }
コード例 #3
0
        private void OnMouseMove_BeginReorder(Point mousePosition, Point mousePositionGridParent)
        {
            DataGridColumnHeader dragIndicator = new DataGridColumnHeader();

            dragIndicator.OwningColumn    = this.OwningColumn;
            dragIndicator.IsEnabled       = false;
            dragIndicator.Content         = this.Content;
            dragIndicator.ContentTemplate = this.ContentTemplate;

            if (this.OwningColumn.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningColumn.DragIndicatorStyle);
            }
            else if (this.OwningGrid.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningGrid.DragIndicatorStyle);
            }

            // If the user didn't style the dragIndicator's Width, default it to the column header's width
            if (double.IsNaN(dragIndicator.Width))
            {
                dragIndicator.Width = this.ActualWidth;
            }

            // If the user didn't style the dropLocationIndicator's Height, default to the column header's height
            if (double.IsNaN(this.OwningGrid.ColumnDropLocationIndicator.Height))
            {
                this._autoSizeDropLocationIndicatorHeight          = true;
                this.OwningGrid.ColumnDropLocationIndicator.Height = this.ActualHeight;
            }

            // pass the caret's data template to the user for modification
            DataGridColumnReorderingEventArgs columnReorderingEventArgs = new DataGridColumnReorderingEventArgs(this.OwningColumn)
            {
                DropLocationIndicator = this.OwningGrid.ColumnDropLocationIndicator,
                DragIndicator         = dragIndicator
            };

            this.OwningGrid.OnColumnReordering(columnReorderingEventArgs);
            if (columnReorderingEventArgs.Cancel)
            {
                return;
            }

            // The user didn't cancel, so prepare for the reorder
            _dragColumn      = this.OwningColumn;
            _dragMode        = DragMode.Reorder;
            _dragStartParent = mousePositionGridParent;
            // the mouse position relative to the ColumnHeader needs to be scaled to be in the same
            // dimensions as the DataGrid, so that it doesn't get out of sync later on
            _dragStart = this.OwningGrid.RenderTransform.Transform(mousePosition);

            // Display the reordering thumb
            if (_reorderingThumb == null)
            {
                _reorderingThumb = new Popup();
            }

            _reorderingThumb.Child  = columnReorderingEventArgs.DragIndicator;
            _reorderingThumb.IsOpen = true;

            // use the data template to populate the caret
            if (columnReorderingEventArgs.DropLocationIndicator != null)
            {
                Control child = columnReorderingEventArgs.DropLocationIndicator;

                this.OwningGrid.ColumnDropLocationIndicatorPopup.Child  = child;
                this.OwningGrid.ColumnDropLocationIndicatorPopup.Height = child.ActualHeight;
                this.OwningGrid.ColumnDropLocationIndicatorPopup.Width  = child.ActualWidth;

                this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = false;
            }
        }
コード例 #4
0
        private void OnMouseMove_BeginReorder(Point mousePosition)
        {
            DataGridColumnHeader dragIndicator = new DataGridColumnHeader();
            dragIndicator.OwningColumn = this.OwningColumn;
            dragIndicator.IsEnabled = false;
            dragIndicator.Content = this.Content;
            dragIndicator.ContentTemplate = this.ContentTemplate;

            Control dropLocationIndicator = new ContentControl();
            dropLocationIndicator.SetStyleWithType(this.OwningGrid.DropLocationIndicatorStyle);

            if (this.OwningColumn.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningColumn.DragIndicatorStyle);
            }
            else if (this.OwningGrid.DragIndicatorStyle != null)
            {
                dragIndicator.SetStyleWithType(this.OwningGrid.DragIndicatorStyle);
            }

            // If the user didn't style the dragIndicator's Width, default it to the column header's width
            if (double.IsNaN(dragIndicator.Width))
            {
                dragIndicator.Width = this.ActualWidth;
            }

            // If the user didn't style the dropLocationIndicator's Height, default to the column header's height
            if (double.IsNaN(dropLocationIndicator.Height))
            {
                dropLocationIndicator.Height = this.ActualHeight;
            }

            // pass the caret's data template to the user for modification
            DataGridColumnReorderingEventArgs columnReorderingEventArgs = new DataGridColumnReorderingEventArgs(this.OwningColumn)
            {
                DropLocationIndicator = dropLocationIndicator,
                DragIndicator = dragIndicator
            };
            this.OwningGrid.OnColumnReordering(columnReorderingEventArgs);
            if (columnReorderingEventArgs.Cancel)
            {
                return;
            }

            // The user didn't cancel, so prepare for the reorder
            _dragColumn = this.OwningColumn;
            _dragMode = DragMode.Reorder;
            _dragStart = mousePosition;

            // Display the reordering thumb
            this.OwningGrid.ColumnHeaders.DragColumn = this.OwningColumn;
            this.OwningGrid.ColumnHeaders.DragIndicator = columnReorderingEventArgs.DragIndicator;
            this.OwningGrid.ColumnHeaders.DropLocationIndicator = columnReorderingEventArgs.DropLocationIndicator;
        }