private static void EnsureColumnHeaderClip(DataGridColumnHeader columnHeader, double width, double height, double frozenLeftEdge, double columnHeaderLeftEdge)
 {
     // Clip the cell only if it's scrolled under frozen columns.  Unfortunately, we need to clip in this case
     // because cells could be transparent
     if (frozenLeftEdge > columnHeaderLeftEdge)
     {
         RectangleGeometry rg = new RectangleGeometry();
         double xClip = Math.Min(width, frozenLeftEdge - columnHeaderLeftEdge);
         rg.Rect = new Rect(xClip, 0, width - xClip, height);
         columnHeader.Clip = rg;
     }
     else
     {
         columnHeader.Clip = null;
     }
 }
        public FilterSelectionView(AutofilterDataGrid _autofilterDataGrid, string columnName, ObservableCollection<string> columnDataList, DataGridColumnHeader _columnHeader, bool isNumericColumn, Point _relativePoint)
        {
            InitializeComponent();
            this.SelectedColumn = columnName;
            this.autofilterDataGrid = _autofilterDataGrid;
            this.selectedColumnHeader = _columnHeader;
            this.relativePoints = _relativePoint;

            columnTitle = columnName;
            if (_columnHeader != null && !string.IsNullOrEmpty(_columnHeader.Content as string))
            {
                columnTitle = _columnHeader.Content as string;
            }
            this.Title = string.Format("{0} - Selection", columnTitle);

            this.VM.SelectedFilterColumn = this.autofilterDataGrid.GetFilterColumnByName(columnName);

            ObservableCollection<string> sortedColumnDataList = SortData(columnDataList, isNumericColumn);

            //VM.InitFilteredData(columnName, columnDataList);
            VM.RefreshFilteredData(columnName, sortedColumnDataList, this.VM.SelectedFilterColumn);

            if (this.VM.SelectedFilterColumn == null)
            {
                this.VM.SelectedFilterColumn = new FilterColumn();
            }

            this.isNumericColumn = isNumericColumn;

            if (isNumericColumn)
            {
                this.mnuNumeric.IsEnabled = true;
            }
            else
            {
                this.mnuNumeric.IsEnabled = false;
            }

            this.Loaded += new RoutedEventHandler(FilterSelectionView_Loaded);
            this.Closed += new EventHandler(FilterSelectionView_Closed);
        }
        /// <summary>
        ///     Helper method to find display index, header and header start position based on given mouse position
        /// </summary>
        private void FindDisplayIndexAndHeaderPosition(Point startPos, bool findNearestColumn, out int displayIndex, out Point headerPos, out DataGridColumnHeader header)
        {
            Debug.Assert(ParentDataGrid != null, "ParentDataGrid is null");

            Point originPoint = new Point(0, 0);

            headerPos    = originPoint;
            displayIndex = -1;
            header       = null;

            if (startPos.X < 0.0)
            {
                if (findNearestColumn)
                {
                    displayIndex = 0;
                }

                return;
            }

            double   headerStartX       = 0.0;
            double   headerEndX         = 0.0;
            int      i                  = 0;
            DataGrid dataGrid           = ParentDataGrid;
            double   averageColumnWidth = dataGrid.InternalColumns.AverageColumnWidth;
            bool     firstVisibleNonFrozenColumnHandled = false;

            for (i = 0; i < dataGrid.Columns.Count; i++)
            {
                displayIndex++;
                DataGridColumnHeader currentHeader = dataGrid.ColumnHeaderFromDisplayIndex(i);
                if (currentHeader == null)
                {
                    DataGridColumn column = dataGrid.ColumnFromDisplayIndex(i);
                    if (!column.IsVisible)
                    {
                        continue;
                    }
                    else
                    {
                        headerStartX = headerEndX;
                        if (i >= dataGrid.FrozenColumnCount &&
                            !firstVisibleNonFrozenColumnHandled)
                        {
                            headerStartX -= dataGrid.HorizontalScrollOffset;
                            firstVisibleNonFrozenColumnHandled = true;
                        }

                        headerEndX = headerStartX + GetColumnEstimatedWidth(column, averageColumnWidth);
                    }
                }
                else
                {
                    GeneralTransform transform = currentHeader.TransformToAncestor(this);
                    headerStartX = transform.Transform(originPoint).X;
                    headerEndX   = headerStartX + currentHeader.RenderSize.Width;
                }

                if (DoubleUtil.LessThanOrClose(startPos.X, headerStartX))
                {
                    break;
                }

                if (DoubleUtil.GreaterThanOrClose(startPos.X, headerStartX) &&
                    DoubleUtil.LessThanOrClose(startPos.X, headerEndX))
                {
                    if (findNearestColumn)
                    {
                        double headerMidX = (headerStartX + headerEndX) * 0.5;
                        if (DoubleUtil.GreaterThanOrClose(startPos.X, headerMidX))
                        {
                            headerStartX = headerEndX;
                            displayIndex++;
                        }

                        if (_draggingSrcColumnHeader != null && _draggingSrcColumnHeader.Column != null && _draggingSrcColumnHeader.Column.DisplayIndex < displayIndex)
                        {
                            displayIndex--;
                        }
                    }
                    else
                    {
                        header = currentHeader;
                    }

                    break;
                }
            }

            if (i == dataGrid.Columns.Count)
            {
                displayIndex = dataGrid.Columns.Count - 1;
                headerStartX = headerEndX;
            }

            headerPos.X = headerStartX;
            return;
        }
Example #4
0
        public void Load()
        {
            _resultHeaderTags = TagCollection.VirtualTags.Where((dt) => dt.Group.Any((gr) => gr.ToLower().Contains("result"))).ToArray();
            _resultValueTags = TagCollection.DataTags.Where((dt) => dt.Group.Any((gr) => gr.ToLower().Contains("result"))).ToArray();
            _resultSigmaTags = TagCollection.DataTags.Where((dt) => dt.Group.Any((gr) => gr.ToLower().Contains("sigma"))).ToArray();

            _cells = new List<List<ResultCell>>();

            //getting the number of columns
            foreach (DataTag tag in _resultValueTags)
            {
                //number of columns is equal to the highest number in the 'testpointX' data tags

                var tpNum = Regex.Match(tag.Name, @"[\d+]");
                if (tpNum.Success)
                    numCols = Math.Max(numCols, Convert.ToByte(tpNum.Value));
            }

            //add one row to the grid for the column headers
            var rowOne = new RowDefinition();
            rowOne.Name = "columnHeaders";
            rowOne.Height = GridLength.Auto;
            resultsGrid.RowDefinitions.Add(rowOne);
            numRows++;

            //add one column to the grid for the row headers
            var colOne = new ColumnDefinition();
            colOne.Width = GridLength.Auto;
            resultsGrid.ColumnDefinitions.Add(colOne);
            numCols++;

            //adding the columns to the grid
            for (int i = 1; i < numCols; i++)
            {
                var col = new ColumnDefinition();
                col.Name = "Header" + i.ToString();
                resultsGrid.ColumnDefinitions.Add(col);
                ResultsHeader headerBox = new ResultsHeader();
                headerBox.HeaderText = i.ToString();

                DataGridColumnHeader columnHeader = new DataGridColumnHeader();
                columnHeader.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                columnHeader.VerticalContentAlignment = VerticalAlignment.Stretch;

                columnHeader.Content = headerBox;

                Grid.SetColumn(columnHeader, i);
                Grid.SetRow(columnHeader, 0);

                resultsGrid.Children.Add(columnHeader);
            }

            //adding the rows and row headers
            foreach (DataTag tag in _resultHeaderTags)
            {
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = GridLength.Auto;
                rowDef.Name = tag.Name.Split('.').Last(); //So I can find it later, regex removes all non alpha chars
                resultsGrid.RowDefinitions.Add(rowDef);

                ResultsHeader headerBox = new ResultsHeader();
                headerBox.HeaderText = tag.Description;
                //headerBox.headerText.HorizontalAlignment = HorizontalAlignment.Left;
                headerBox.HorizontalAlignment = HorizontalAlignment.Stretch;

                DataGridRowHeader rowHeader = new DataGridRowHeader();
                rowHeader.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                rowHeader.VerticalContentAlignment = VerticalAlignment.Stretch;
                rowHeader.HorizontalAlignment = HorizontalAlignment.Stretch;

                rowHeader.Content = headerBox;

                Grid.SetRow(rowHeader, resultsGrid.RowDefinitions.Count - 1);
                Grid.SetColumn(rowHeader, 0);
                resultsGrid.Children.Add(rowHeader);
                numRows++;
            }

            //adding the result cells
            for (int row = 0; row < numRows; row++)
            {
                if (row == 0)
                {
                    _cells.Add(null);
                    continue;
                }
                else _cells.Add(new List<ResultCell>());

                for (int col = 0; col < numCols; col++)
                {
                    if (col == 0)
                    {
                        _cells[row].Add(null);
                        continue;
                    }

                    var cell = new ResultCell();

                    Grid.SetColumn(cell, col);
                    Grid.SetRow(cell, row);

                    _cells[row].Add(cell);
                    resultsGrid.Children.Add(cell);
                }
            }

            //creating the highlight and setting it's length
            _highlight = new Rectangle();
            _highlight.Fill = new SolidColorBrush(Color.FromArgb(255 / 2, 255, 255, 0));
            _highlight.Visibility = Visibility.Hidden;
            resultsGrid.Children.Add(_highlight);
            Grid.SetRowSpan(_highlight, numRows);
            Grid.SetZIndex(_highlight, 2); // must be between 0 and 5

            curTestPoint = TagCollection.Get("CurrentTestPoint");
            curTestPoint.ValueSet += curTestPoint_ValueSet;
            curTestPoint.ValueChanged += curTestPoint_ValueSet;

            //keeping the result values updated
            foreach (DataTag result in _resultValueTags)
            {
                result.ValueChanged += result_ValueChanged;
                result.ValueSet += result_ValueChanged;
            }

            foreach (DataTag sigma in _resultSigmaTags)
            {
                sigma.ValueChanged += result_ValueChanged;
                sigma.ValueSet += result_ValueChanged;
            }
        }
 /// <summary>
 ///     Method which prepares the state for the start of column header drag 
 /// </summary>
 private void PrepareColumnHeaderDrag(DataGridColumnHeader header, Point pos, Point relativePos) 
 { 
     _prepareColumnHeaderDragging = true;
     _isColumnHeaderDragging = false; 
     _draggingSrcColumnHeader = header;
     _columnHeaderDragStartPosition = pos;
     _columnHeaderDragStartRelativePosition = relativePos;
 } 
 /// <summary>
 /// AutomationPeer for DataGridColumnHeader
 /// </summary>
 /// <param name="owner">DataGridColumnHeader</param>
 public DataGridColumnHeaderAutomationPeer(DataGridColumnHeader owner)
     : base(owner)
 {
 }
Example #7
0
        // Token: 0x06005CD3 RID: 23763 RVA: 0x001A1F14 File Offset: 0x001A0114
        private static object OnCoerceStringFormat(DependencyObject d, object baseValue)
        {
            DataGridColumnHeader dataGridColumnHeader = d as DataGridColumnHeader;

            return(DataGridHelper.GetCoercedTransferPropertyValue(dataGridColumnHeader, baseValue, ContentControl.ContentStringFormatProperty, dataGridColumnHeader.Column, DataGridColumn.HeaderStringFormatProperty));
        }
        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;
            }
        }
Example #9
0
        private void OnMouseMove_Reorder(ref bool handled, Point mousePosition, Point mousePositionHeaders, Point mousePositionGrid, Point mousePositionGridParent, double distanceFromLeft, double distanceFromRight)
        {
            if (handled)
            {
                return;
            }

            #region handle entry into reorder mode
            if (_dragMode == DragMode.MouseDown && _dragColumn == null && (distanceFromRight > DATAGRIDCOLUMNHEADER_resizeRegionWidth && distanceFromLeft > DATAGRIDCOLUMNHEADER_resizeRegionWidth))
            {
                DragStartedEventArgs dragStartedEventArgs = new DragStartedEventArgs(mousePositionGrid.X - _lastMousePositionGrid.Value.X, mousePositionGrid.Y - _lastMousePositionGrid.Value.Y);
                this.OwningGrid.OnColumnHeaderDragStarted(dragStartedEventArgs);

                handled = CanReorderColumn(this.OwningColumn);

                if (handled)
                {
                    DataGridColumnHeader dragIndicator = new DataGridColumnHeader();
                    dragIndicator.OwningColumn = this.OwningColumn;
                    dragIndicator.IsEnabled = false;
                    dragIndicator.Content = this.Content;
                    dragIndicator.ContentTemplate = this.ContentTemplate;

                    if (this.OwningGrid.DragIndicatorStyle != null)
                    {
                        dragIndicator.Style = 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.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;
                    }
                }
            }
            #endregion

            #region handle reorder mode (eg, positioning of the popup)
            if (_dragMode == DragMode.Reorder && _reorderingThumb != null)
            {
                DragDeltaEventArgs dragDeltaEventArgs = new DragDeltaEventArgs(mousePositionGrid.X - _lastMousePositionGrid.Value.X, mousePositionGrid.Y - _lastMousePositionGrid.Value.Y);
                this.OwningGrid.OnColumnHeaderDragDelta(dragDeltaEventArgs);

                _reorderingThumb.HorizontalOffset = mousePositionGridParent.X - _dragStart.Value.X;
                _reorderingThumb.VerticalOffset = _dragStartParent.Value.Y - _dragStart.Value.Y;

                // the mouse position relative to the ColumnHeadersPresenter can be scaled differently than
                // the same position relative to the DataGrid, so apply the grid's RenderTransform
                Point scaledMousePositionHeaders = this.OwningGrid.RenderTransform.Transform(mousePositionHeaders);

                // prepare some variables for clipping/hiding
                double dgX = mousePositionGridParent.X - scaledMousePositionHeaders.X;
                double dgY = mousePositionGridParent.Y - scaledMousePositionHeaders.Y;
                double dgW = this.OwningGrid.CellsWidth;
                double dgH = this.OwningGrid.CellsHeight + this.OwningGrid.ColumnHeaders.ActualHeight;

                // we need to transform the size of the clipping rectangle if the datagrid has a rendertransform set
                Point clipSize = new Point(dgW, dgH);
                clipSize = this.OwningGrid.RenderTransform.Transform(clipSize);

                // clip the thumb to the column headers region
                _reorderingThumb.Child.Clip = new RectangleGeometry
                {
                    Rect = new Rect(
                        dgX - _reorderingThumb.HorizontalOffset,
                        dgY - _reorderingThumb.VerticalOffset,
                        clipSize.X,
                        clipSize.Y
                        )
                };

                // if the datagrid has a scale transform, apply the inverse to the popup's clipping rectangle
                ScaleTransform scaleTransform = null;
                ScaleTransform gridScaleTransform = _reorderingThumb.Child.RenderTransform as ScaleTransform;
                if (gridScaleTransform != null && gridScaleTransform.ScaleY != 0.0 && gridScaleTransform.ScaleX != 0.0)
                {
                    scaleTransform = new ScaleTransform();
                    scaleTransform.ScaleX = 1.0 / gridScaleTransform.ScaleX;
                    scaleTransform.ScaleY = 1.0 / gridScaleTransform.ScaleY;
                }
                if (scaleTransform != null)
                {
                    _reorderingThumb.Child.Clip.Transform = scaleTransform;
                }

                // Find header we're hovering over
                DataGridColumn targetColumn = this.GetReorderingTargetColumn(mousePosition, true /* ignoreVertical */, true /* clipToVisible */);

                if (this.OwningGrid.ColumnDropLocationIndicator != null)
                {
                    if (targetColumn == this.OwningGrid.ColumnsInternal.FillerColumn)
                    {
                        // change target column to last column but position caret at the end

                        targetColumn = this.OwningGrid.ColumnsInternal.LastVisibleColumn;

                        Point targetPosition = this.OwningGrid.RenderTransform.Transform(this.Translate(targetColumn.HeaderCell, mousePosition));

                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = true;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset = mousePositionGridParent.X - targetPosition.X + targetColumn.HeaderCell.ActualWidth;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.VerticalOffset = mousePositionGridParent.Y - targetPosition.Y;
                    }
                    else if (targetColumn != null)
                    {
                        // try to position caret

                        Point targetPosition = this.OwningGrid.RenderTransform.Transform(this.Translate(targetColumn.HeaderCell, mousePosition));

                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = true;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset = mousePositionGridParent.X - targetPosition.X;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.VerticalOffset = mousePositionGridParent.Y - targetPosition.Y;
                    }
                    else
                    {
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = false;
                    }

                    // hide the caret if it's off the grid -- this is not the same as clipping
                    if (this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset < dgX
                        || dgX + clipSize.X < this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset)
                    {
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = false;
                    }
                }

                handled = true;
            }
            #endregion
        }
Example #10
0
        internal virtual DataGridColumnHeader CreateHeader()
        {
            DataGridColumnHeader result = new DataGridColumnHeader();

            // Take the style set on this column or the one defined at the DataGrid level
            Style style = this.HeaderStyle;
            if (style == null && this.OwningGrid != null)
            {
                style = this.OwningGrid.ColumnHeaderStyle;
            }
            if (style != null)
            {
                result.Style = style;
            }

            result.OwningColumn = this;
            result.Content = this._header;

            return result;
        }
Example #11
0
        private void OnMouseMove_Reorder(ref bool handled, Point mousePosition, Point mousePositionHeaders, Point mousePositionGrid, Point mousePositionGridParent, double distanceFromLeft, double distanceFromRight)
        {
            if (handled)
            {
                return;
            }

            #region handle entry into reorder mode
            if (_dragMode == DragMode.MouseDown && _dragColumn == null && (distanceFromRight > DATAGRIDCOLUMNHEADER_resizeRegionWidth && distanceFromLeft > DATAGRIDCOLUMNHEADER_resizeRegionWidth))
            {
                DragStartedEventArgs dragStartedEventArgs = new DragStartedEventArgs(mousePositionGrid.X - _lastMousePositionGrid.Value.X, mousePositionGrid.Y - _lastMousePositionGrid.Value.Y);
                this.OwningGrid.OnColumnHeaderDragStarted(dragStartedEventArgs);

                handled = CanReorderColumn(this.OwningColumn);

                if (handled)
                {
                    DataGridColumnHeader dragIndicator = new DataGridColumnHeader();
                    dragIndicator.OwningColumn    = this.OwningColumn;
                    dragIndicator.IsEnabled       = false;
                    dragIndicator.Content         = this.Content;
                    dragIndicator.ContentTemplate = this.ContentTemplate;

                    if (this.OwningGrid.DragIndicatorStyle != null)
                    {
                        dragIndicator.Style = 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.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;
                    }
                }
            }
            #endregion

            #region handle reorder mode (eg, positioning of the popup)
            if (_dragMode == DragMode.Reorder && _reorderingThumb != null)
            {
                DragDeltaEventArgs dragDeltaEventArgs = new DragDeltaEventArgs(mousePositionGrid.X - _lastMousePositionGrid.Value.X, mousePositionGrid.Y - _lastMousePositionGrid.Value.Y);
                this.OwningGrid.OnColumnHeaderDragDelta(dragDeltaEventArgs);

                _reorderingThumb.HorizontalOffset = mousePositionGridParent.X - _dragStart.Value.X;
                _reorderingThumb.VerticalOffset   = _dragStartParent.Value.Y - _dragStart.Value.Y;

                // the mouse position relative to the ColumnHeadersPresenter can be scaled differently than
                // the same position relative to the DataGrid, so apply the grid's RenderTransform
                Point scaledMousePositionHeaders = this.OwningGrid.RenderTransform.Transform(mousePositionHeaders);

                // prepare some variables for clipping/hiding
                double dgX = mousePositionGridParent.X - scaledMousePositionHeaders.X;
                double dgY = mousePositionGridParent.Y - scaledMousePositionHeaders.Y;
                double dgW = this.OwningGrid.CellsWidth;
                double dgH = this.OwningGrid.CellsHeight + this.OwningGrid.ColumnHeaders.ActualHeight;

                // we need to transform the size of the clipping rectangle if the datagrid has a rendertransform set
                Point clipSize = new Point(dgW, dgH);
                clipSize = this.OwningGrid.RenderTransform.Transform(clipSize);

                // clip the thumb to the column headers region
                _reorderingThumb.Child.Clip = new RectangleGeometry
                {
                    Rect = new Rect(
                        dgX - _reorderingThumb.HorizontalOffset,
                        dgY - _reorderingThumb.VerticalOffset,
                        clipSize.X,
                        clipSize.Y
                        )
                };

                // if the datagrid has a scale transform, apply the inverse to the popup's clipping rectangle
                ScaleTransform scaleTransform     = null;
                ScaleTransform gridScaleTransform = _reorderingThumb.Child.RenderTransform as ScaleTransform;
                if (gridScaleTransform != null && gridScaleTransform.ScaleY != 0.0 && gridScaleTransform.ScaleX != 0.0)
                {
                    scaleTransform        = new ScaleTransform();
                    scaleTransform.ScaleX = 1.0 / gridScaleTransform.ScaleX;
                    scaleTransform.ScaleY = 1.0 / gridScaleTransform.ScaleY;
                }
                if (scaleTransform != null)
                {
                    _reorderingThumb.Child.Clip.Transform = scaleTransform;
                }

                // Find header we're hovering over
                DataGridColumn targetColumn = this.GetReorderingTargetColumn(mousePosition, true /* ignoreVertical */, true /* clipToVisible */);

                if (this.OwningGrid.ColumnDropLocationIndicator != null)
                {
                    if (targetColumn == this.OwningGrid.ColumnsInternal.FillerColumn)
                    {
                        // change target column to last column but position caret at the end

                        targetColumn = this.OwningGrid.ColumnsInternal.LastVisibleColumn;

                        Point targetPosition = this.OwningGrid.RenderTransform.Transform(this.Translate(targetColumn.HeaderCell, mousePosition));

                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen           = true;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset = mousePositionGridParent.X - targetPosition.X + targetColumn.HeaderCell.ActualWidth;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.VerticalOffset   = mousePositionGridParent.Y - targetPosition.Y;
                    }
                    else if (targetColumn != null)
                    {
                        // try to position caret

                        Point targetPosition = this.OwningGrid.RenderTransform.Transform(this.Translate(targetColumn.HeaderCell, mousePosition));

                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen           = true;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset = mousePositionGridParent.X - targetPosition.X;
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.VerticalOffset   = mousePositionGridParent.Y - targetPosition.Y;
                    }
                    else
                    {
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = false;
                    }

                    // hide the caret if it's off the grid -- this is not the same as clipping
                    if (this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset < dgX ||
                        dgX + clipSize.X < this.OwningGrid.ColumnDropLocationIndicatorPopup.HorizontalOffset)
                    {
                        this.OwningGrid.ColumnDropLocationIndicatorPopup.IsOpen = false;
                    }
                }

                handled = true;
            }
            #endregion
        }
        /// <summary>
        /// Measures the children of a <see cref="T:System.Windows.Controls.Primitives.DataGridColumnHeadersPresenter" /> to
        /// prepare for arranging them during the <see cref="M:System.Windows.FrameworkElement.ArrangeOverride(System.Windows.Size)" /> pass.
        /// </summary>
        /// <param name="availableSize">
        /// The available size that this element can give to child elements. Indicates an upper limit that child elements should not exceed.
        /// </param>
        /// <returns>
        /// The size that the <see cref="T:System.Windows.Controls.Primitives.DataGridColumnHeadersPresenter" /> determines it needs during layout, based on its calculations of child object allocated sizes.
        /// </returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            if (this.OwningGrid == null)
            {
                return(base.MeasureOverride(availableSize));
            }
            if (!this.OwningGrid.AreColumnHeadersVisible)
            {
                return(Size.Empty);
            }
            double height = this.OwningGrid.ColumnHeaderHeight;
            bool   autoSizeHeight;

            if (double.IsNaN(height))
            {
                // No explicit height values were set so we can autosize
                height         = 0;
                autoSizeHeight = true;
            }
            else
            {
                autoSizeHeight = false;
            }

            double         measureWidth;
            DataGridColumn lastVisibleColumn = this.OwningGrid.ColumnsInternal.LastVisibleColumn;

            foreach (DataGridColumn column in this.OwningGrid.ColumnsInternal.GetVisibleColumns())
            {
                DataGridLength columnWidth = column.EffectiveWidth;
                measureWidth = columnWidth.IsAbsolute ? column.ActualWidth : column.ActualMaxWidth;
                bool autoGrowWidth = columnWidth.IsAuto || columnWidth.IsSizeToHeader;

                DataGridColumnHeader columnHeader = column.HeaderCell;
                if (column != lastVisibleColumn)
                {
                    columnHeader.UpdateSeparatorVisibility(lastVisibleColumn);
                }
                columnHeader.Measure(new Size(measureWidth, double.PositiveInfinity));
                if (autoSizeHeight)
                {
                    height = Math.Max(height, columnHeader.DesiredSize.Height);
                }
                if (autoGrowWidth && columnHeader.DesiredSize.Width > column.DesiredWidth)
                {
                    column.DesiredWidth = columnHeader.DesiredSize.Width;
                }
            }

            // Add the filler column if it's not represented.  We won't know whether we need it or not until Arrange
            DataGridFillerColumn fillerColumn = this.OwningGrid.ColumnsInternal.FillerColumn;

            if (!fillerColumn.IsRepresented)
            {
                Debug.Assert(!this.Children.Contains(fillerColumn.HeaderCell));
                fillerColumn.HeaderCell.SeparatorVisibility = Visibility.Collapsed;
                this.Children.Insert(this.OwningGrid.ColumnsInternal.Count, fillerColumn.HeaderCell);
                fillerColumn.IsRepresented = true;
                // Optimize for the case where we don't need the filler cell
                fillerColumn.HeaderCell.Visibility = Visibility.Collapsed;
            }
            fillerColumn.HeaderCell.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            return(new Size(this.OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth, height));
        }
        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;
        }
Example #14
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;
            }
        }
Example #15
0
 /// <summary>
 /// Creates a TestHook for the given DataGridColumnHeader
 /// </summary>
 /// <param name="columnHeader">DataGridColumnHeader</param>
 internal InternalTestHook(DataGridColumnHeader columnHeader)
 {
     this._columnHeader = columnHeader;
 }
Example #16
0
        private void ColumnHeaderMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var header = ((FrameworkElement)sender).Tag as DataGridColumnHeader;
            if (header != null)
            {
                // 通过HeaderName找到对应的Column
                string headerName = header.Content.ToString();
                var column = RecordsGrid.Columns.Where(col => col.Header.ToString() == headerName).Single();

                // 只对可以排序的Column进行处理
                if (column.CanUserSort)
                {
                    var newSortName = string.IsNullOrWhiteSpace(column.SortMemberPath) ? headerName : column.SortMemberPath.Trim();
                    if (newSortName == _sortName)
                    {
                        _sortDir = _sortDir == SortDir.ASC ? SortDir.DESC : SortDir.ASC;
                    }
                    else
                    {
                        _sortName = newSortName;
                        _sortDir = SortDir.ASC;
                    }

                    // 设置箭头状态
                    string sortState = _sortDir == SortDir.ASC ? "SortAsc" : "SortDesc";
                    VisualStateManager.GoToState(header, sortState, true);
                    if (_currSortColumnHeader != null && _currSortColumnHeader != header)
                    {
                        VisualStateManager.GoToState(_currSortColumnHeader, "Unsort", false);
                    }
                    _currSortColumnHeader = header;

                    // 查询
                    QueryRecords();
                }
            }

            e.Handled = true;
        }
        // Token: 0x06005CF8 RID: 23800 RVA: 0x001A27E0 File Offset: 0x001A09E0
        private DataGridColumn ColumnFromContainer(DataGridColumnHeader container)
        {
            int index = base.ItemContainerGenerator.IndexFromContainer(container);

            return(this.HeaderCollection.ColumnFromIndex(index));
        }
Example #18
0
        /// <summary>
        /// Method which recomputes the widths of columns on resize of a header
        /// </summary>
        private static void RecomputeColumnWidthsOnColumnResize(DataGridColumnHeader header, double horizontalChange)
        {
            Debug.Assert(header != null, "Header should not be null");

            DataGridColumn resizingColumn = header.Column;
            if (resizingColumn == null)
            {
                return;
            }

            DataGrid dataGrid = resizingColumn.DataGridOwner;
            if (dataGrid == null)
            {
                return;
            }

            dataGrid.InternalColumns.RecomputeColumnWidthsOnColumnResize(resizingColumn, horizontalChange, false);
        }
        // Token: 0x06005CFA RID: 23802 RVA: 0x001A2818 File Offset: 0x001A0A18
        internal void NotifyPropertyChanged(DependencyObject d, string propertyName, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget target)
        {
            DataGridColumn dataGridColumn = d as DataGridColumn;

            if (DataGridHelper.ShouldNotifyColumnHeadersPresenter(target))
            {
                if (e.Property == DataGridColumn.WidthProperty || e.Property == DataGridColumn.DisplayIndexProperty)
                {
                    if (dataGridColumn.IsVisible)
                    {
                        this.InvalidateDataGridCellsPanelMeasureAndArrange();
                    }
                }
                else if (e.Property == DataGrid.FrozenColumnCountProperty || e.Property == DataGridColumn.VisibilityProperty || e.Property == DataGrid.CellsPanelHorizontalOffsetProperty || string.Compare(propertyName, "ViewportWidth", StringComparison.Ordinal) == 0 || string.Compare(propertyName, "DelayedColumnWidthComputation", StringComparison.Ordinal) == 0)
                {
                    this.InvalidateDataGridCellsPanelMeasureAndArrange();
                }
                else if (e.Property == DataGrid.HorizontalScrollOffsetProperty)
                {
                    base.InvalidateArrange();
                    this.InvalidateDataGridCellsPanelMeasureAndArrange();
                }
                else if (string.Compare(propertyName, "RealizedColumnsBlockListForNonVirtualizedRows", StringComparison.Ordinal) == 0)
                {
                    this.InvalidateDataGridCellsPanelMeasureAndArrange(false);
                }
                else if (string.Compare(propertyName, "RealizedColumnsBlockListForVirtualizedRows", StringComparison.Ordinal) == 0)
                {
                    this.InvalidateDataGridCellsPanelMeasureAndArrange(true);
                }
                else if (e.Property == DataGrid.CellsPanelActualWidthProperty)
                {
                    base.InvalidateArrange();
                }
                else if (e.Property == DataGrid.EnableColumnVirtualizationProperty)
                {
                    DataGridHelper.TransferProperty(this, VirtualizingPanel.IsVirtualizingProperty);
                }
            }
            if (DataGridHelper.ShouldNotifyColumnHeaders(target))
            {
                if (e.Property == DataGridColumn.HeaderProperty)
                {
                    if (this.HeaderCollection != null)
                    {
                        this.HeaderCollection.NotifyHeaderPropertyChanged(dataGridColumn, e);
                        return;
                    }
                }
                else
                {
                    for (ContainerTracking <DataGridColumnHeader> containerTracking = this._headerTrackingRoot; containerTracking != null; containerTracking = containerTracking.Next)
                    {
                        containerTracking.Container.NotifyPropertyChanged(d, e);
                    }
                    if (d is DataGrid && (e.Property == DataGrid.ColumnHeaderStyleProperty || e.Property == DataGrid.ColumnHeaderHeightProperty))
                    {
                        DataGridColumnHeader dataGridColumnHeader = base.GetTemplateChild("PART_FillerColumnHeader") as DataGridColumnHeader;
                        if (dataGridColumnHeader != null)
                        {
                            dataGridColumnHeader.NotifyPropertyChanged(d, e);
                        }
                    }
                }
            }
        }
Example #20
0
        // Token: 0x06005CD2 RID: 23762 RVA: 0x001A1EE8 File Offset: 0x001A00E8
        private static object OnCoerceContentTemplateSelector(DependencyObject d, object baseValue)
        {
            DataGridColumnHeader dataGridColumnHeader = d as DataGridColumnHeader;

            return(DataGridHelper.GetCoercedTransferPropertyValue(dataGridColumnHeader, baseValue, ContentControl.ContentTemplateSelectorProperty, dataGridColumnHeader.Column, DataGridColumn.HeaderTemplateSelectorProperty));
        }
        // Token: 0x06005D16 RID: 23830 RVA: 0x001A3244 File Offset: 0x001A1444
        private void FindDisplayIndexAndHeaderPosition(Point startPos, bool findNearestColumn, out int displayIndex, out Point headerPos, out DataGridColumnHeader header)
        {
            Point point = new Point(0.0, 0.0);

            headerPos    = point;
            displayIndex = -1;
            header       = null;
            if (startPos.X < 0.0)
            {
                if (findNearestColumn)
                {
                    displayIndex = 0;
                }
                return;
            }
            double   num                = 0.0;
            double   num2               = 0.0;
            DataGrid parentDataGrid     = this.ParentDataGrid;
            double   averageColumnWidth = parentDataGrid.InternalColumns.AverageColumnWidth;
            bool     flag               = false;
            int      i = 0;

            while (i < parentDataGrid.Columns.Count)
            {
                displayIndex++;
                DataGridColumnHeader dataGridColumnHeader = parentDataGrid.ColumnHeaderFromDisplayIndex(i);
                if (dataGridColumnHeader != null)
                {
                    GeneralTransform generalTransform = dataGridColumnHeader.TransformToAncestor(this);
                    num  = generalTransform.Transform(point).X;
                    num2 = num + dataGridColumnHeader.RenderSize.Width;
                    goto IL_FB;
                }
                DataGridColumn dataGridColumn = parentDataGrid.ColumnFromDisplayIndex(i);
                if (dataGridColumn.IsVisible)
                {
                    num = num2;
                    if (i >= parentDataGrid.FrozenColumnCount && !flag)
                    {
                        num -= parentDataGrid.HorizontalScrollOffset;
                        flag = true;
                    }
                    num2 = num + DataGridColumnHeadersPresenter.GetColumnEstimatedWidth(dataGridColumn, averageColumnWidth);
                    goto IL_FB;
                }
IL_18D:
                i++;
                continue;
IL_FB:
                if (DoubleUtil.LessThanOrClose(startPos.X, num))
                {
                    break;
                }
                if (!DoubleUtil.GreaterThanOrClose(startPos.X, num) || !DoubleUtil.LessThanOrClose(startPos.X, num2))
                {
                    goto IL_18D;
                }
                if (!findNearestColumn)
                {
                    header = dataGridColumnHeader;
                    break;
                }
                double value = (num + num2) * 0.5;
                if (DoubleUtil.GreaterThanOrClose(startPos.X, value))
                {
                    num = num2;
                    displayIndex++;
                }
                if (this._draggingSrcColumnHeader != null && this._draggingSrcColumnHeader.Column != null && this._draggingSrcColumnHeader.Column.DisplayIndex < displayIndex)
                {
                    displayIndex--;
                    break;
                }
                break;
            }
            if (i == parentDataGrid.Columns.Count)
            {
                displayIndex = parentDataGrid.Columns.Count - 1;
                num          = num2;
            }
            headerPos.X = num;
        }
        internal virtual DataGridColumnHeader CreateHeader()
        {
            DataGridColumnHeader result = new DataGridColumnHeader();
            result.OwningColumn = this;
            result.Content = this._header;
            result.EnsureStyle(null);

            return result;
        }
 /// <summary>
 /// Creates a TestHook for the given DataGridColumnHeader
 /// </summary>
 /// <param name="columnHeader">DataGridColumnHeader</param>
 internal InternalTestHook(DataGridColumnHeader columnHeader)
 {
     this._columnHeader = columnHeader;
 }
        private DataGridColumn ColumnFromContainer(DataGridColumnHeader container) 
        { 
            Debug.Assert(HeaderCollection != null, "This is a helper method for preparing and clearing a container; if it's called we must have a valid ItemSource");
 
            int index = ItemContainerGenerator.IndexFromContainer(container);
            return HeaderCollection.ColumnFromIndex(index);
        }
        /// <summary>
        ///     Notification for column header-related DependencyProperty changes from the grid or from columns.
        /// </summary>
        internal void NotifyPropertyChanged(DependencyObject d, string propertyName, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget target)
        {
            DataGridColumn column = d as DataGridColumn;

            if (DataGridHelper.ShouldNotifyColumnHeadersPresenter(target))
            {
                if (e.Property == DataGridColumn.WidthProperty ||
                    e.Property == DataGridColumn.DisplayIndexProperty)
                {
                    if (column.IsVisible)
                    {
                        InvalidateDataGridCellsPanelMeasureAndArrange();
                    }
                }
                else if (e.Property == DataGrid.FrozenColumnCountProperty ||
                         e.Property == DataGridColumn.VisibilityProperty ||
                         e.Property == DataGrid.CellsPanelHorizontalOffsetProperty ||
                         string.Compare(propertyName, "ViewportWidth", StringComparison.Ordinal) == 0 ||
                         string.Compare(propertyName, "DelayedColumnWidthComputation", StringComparison.Ordinal) == 0)
                {
                    InvalidateDataGridCellsPanelMeasureAndArrange();
                }
                else if (e.Property == DataGrid.HorizontalScrollOffsetProperty)
                {
                    InvalidateArrange();
                    InvalidateDataGridCellsPanelMeasureAndArrange();
                }
                else if (string.Compare(propertyName, "RealizedColumnsBlockListForNonVirtualizedRows", StringComparison.Ordinal) == 0)
                {
                    InvalidateDataGridCellsPanelMeasureAndArrange(/* withColumnVirtualization */ false);
                }
                else if (string.Compare(propertyName, "RealizedColumnsBlockListForVirtualizedRows", StringComparison.Ordinal) == 0)
                {
                    InvalidateDataGridCellsPanelMeasureAndArrange(/* withColumnVirtualization */ true);
                }
                else if (e.Property == DataGrid.CellsPanelActualWidthProperty)
                {
                    InvalidateArrange();
                }
                else if (e.Property == DataGrid.EnableColumnVirtualizationProperty)
                {
                    DataGridHelper.TransferProperty(this, VirtualizingPanel.IsVirtualizingProperty);
                }
            }

            if (DataGridHelper.ShouldNotifyColumnHeaders(target))
            {
                if (e.Property == DataGridColumn.HeaderProperty)
                {
                    if (HeaderCollection != null)
                    {
                        HeaderCollection.NotifyHeaderPropertyChanged(column, e);
                    }
                }
                else
                {
                    // Notify the DataGridColumnHeader objects about property changes
                    ContainerTracking <DataGridColumnHeader> tracker = _headerTrackingRoot;

                    while (tracker != null)
                    {
                        tracker.Container.NotifyPropertyChanged(d, e);
                        tracker = tracker.Next;
                    }

                    // Handle Style & Height change notification for PART_FillerColumnHeader.
                    if (d is DataGrid &&
                        (e.Property == DataGrid.ColumnHeaderStyleProperty || e.Property == DataGrid.ColumnHeaderHeightProperty))
                    {
                        DataGridColumnHeader fillerColumnHeader = GetTemplateChild(ElementFillerColumnHeader) as DataGridColumnHeader;
                        if (fillerColumnHeader != null)
                        {
                            fillerColumnHeader.NotifyPropertyChanged(d, e);
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Helper method to find display index, header and header start position based on given mouse position 
        /// </summary>
        private void FindDisplayIndexAndHeaderPosition(Point startPos, bool findNearestColumn, out int displayIndex, out Point headerPos, out DataGridColumnHeader header) 
        { 
            Debug.Assert(ParentDataGrid != null, "ParentDataGrid is null");
 
            Point originPoint = new Point(0, 0);
            headerPos = originPoint;
            displayIndex = -1;
            header = null; 

            if (startPos.X < 0.0) 
            { 
                if (findNearestColumn)
                { 
                    displayIndex = 0;
                }

                return; 
            }
 
            double headerStartX = 0.0; 
            double headerEndX = 0.0;
            int i = 0; 
            DataGrid dataGrid = ParentDataGrid;
            double averageColumnWidth = dataGrid.InternalColumns.AverageColumnWidth;
            bool firstVisibleNonFrozenColumnHandled = false;
            for (i = 0; i < dataGrid.Columns.Count; i++) 
            {
                displayIndex++; 
                DataGridColumnHeader currentHeader = dataGrid.ColumnHeaderFromDisplayIndex(i); 
                if (currentHeader == null)
                { 
                    DataGridColumn column = dataGrid.ColumnFromDisplayIndex(i);
                    if (!column.IsVisible)
                    {
                        continue; 
                    }
                    else 
                    { 
                        headerStartX = headerEndX;
                        if (i >= dataGrid.FrozenColumnCount && 
                            !firstVisibleNonFrozenColumnHandled)
                        {
                            headerStartX -= dataGrid.HorizontalScrollOffset;
                            firstVisibleNonFrozenColumnHandled = true; 
                        }
 
                        headerEndX = headerStartX + GetColumnEstimatedWidth(column, averageColumnWidth); 
                    }
                } 
                else
                {
                    GeneralTransform transform = currentHeader.TransformToAncestor(this);
                    headerStartX = transform.Transform(originPoint).X; 
                    headerEndX = headerStartX + currentHeader.RenderSize.Width;
                } 
 
                if (DoubleUtil.LessThanOrClose(startPos.X, headerStartX))
                { 
                    break;
                }

                if (DoubleUtil.GreaterThanOrClose(startPos.X, headerStartX) && 
                    DoubleUtil.LessThanOrClose(startPos.X, headerEndX))
                { 
                    if (findNearestColumn) 
                    {
                        double headerMidX = (headerStartX + headerEndX) * 0.5; 
                        if (DoubleUtil.GreaterThanOrClose(startPos.X, headerMidX))
                        {
                            headerStartX = headerEndX;
                            displayIndex++; 
                        }
 
                        if (_draggingSrcColumnHeader != null && _draggingSrcColumnHeader.Column != null && _draggingSrcColumnHeader.Column.DisplayIndex < displayIndex) 
                        {
                            displayIndex--; 
                        }
                    }
                    else
                    { 
                        header = currentHeader;
                    } 
 
                    break;
                } 
            }

            if (i == dataGrid.Columns.Count)
            { 
                displayIndex = dataGrid.Columns.Count - 1;
                headerStartX = headerEndX; 
            } 

            headerPos.X = headerStartX; 
            return;
        }
Example #27
0
        internal void OnResultsGridColumnHeaderClick(DataGridColumnHeader dataGridColumnHeader, DataGrid resultDataGrid, BaseHelperData rawTableData)
        {
            if (!IsTwoColumnSortingEnabled) return;
            var tableData = (DisplayableHelperData) rawTableData;

            var colName = dataGridColumnHeader.Column.SortMemberPath;

            if (tableData.SortingData.FirstColumnName == null)
            {
                // Выбор первой колонки
                tableData.SortingData.FirstColumnName = colName;
                tableData.SortingData.FirstColumnDirection = ListSortDirection.Ascending;

                tableData.NotifyPropertyChanged("FirstOfTwoSortingColumnsText");
            }
            else if (tableData.SortingData.SecondColumnName == null)
            {
                if (tableData.SortingData.FirstColumnName == colName)
                {
                    // Повторный клик на первой колонке, до выбора второй -- инвертируем направление
                    tableData.SortingData.FirstColumnDirection = tableData.SortingData.FirstColumnDirection ==
                                                                  ListSortDirection.Ascending
                        ? ListSortDirection.Descending
                        : ListSortDirection.Ascending;
                }
                else
                {
                    // Выбор второй колонки
                    tableData.SortingData.SecondColumnName = colName;
                    tableData.SortingData.SecondColumnDirection = ListSortDirection.Ascending;

                    tableData.NotifyPropertyChanged("SecondOfTwoSortingColumnsText");
                }
            }
            else
            {
                if (tableData.SortingData.SecondColumnName == colName)
                {
                    // Повторный клик на второй колонке -- инвертируем направление
                    tableData.SortingData.SecondColumnDirection = tableData.SortingData.SecondColumnDirection ==
                                                                   ListSortDirection.Ascending
                        ? ListSortDirection.Descending
                        : ListSortDirection.Ascending;
                }
                else
                {
                    // Клик на третьей колонке -- начинаем все сначала
                    tableData.SortingData.FirstColumnName = colName;
                    tableData.SortingData.FirstColumnDirection = ListSortDirection.Ascending;
                    tableData.SortingData.SecondColumnName = null;

                    tableData.NotifyPropertyChanged("FirstOfTwoSortingColumnsText");
                    tableData.NotifyPropertyChanged("SecondOfTwoSortingColumnsText");
                }

            }

            ApplySorting(resultDataGrid, tableData.SortingData);
        }