private static void OnParentDataGridChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DataGridScrollViewer scrollViewer = sender as DataGridScrollViewer; if (scrollViewer != null) { if (e.NewValue == null) { scrollViewer.ClearScrollViewerList(); } } }
private static void OnSynchronizedScrollViewerExtentPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { DataGridScrollViewer dataGridScrollViewer = o as DataGridScrollViewer; if (dataGridScrollViewer != null) { FrameworkElement panel = dataGridScrollViewer.ScrollInfo as FrameworkElement; if (panel != null) { panel.InvalidateMeasure(); } } }
public void CalculateColumnStretchWidths(double widthToDistribute, ColumnStretchMode columnStretchMode, double columnStretchMinWidth, bool canIncreaseColumnWidth) { if (m_columnStretchingDisabled) { return; } int currentDataGridScrollViewerMeasureVersion = 0; DataGridControl dataGridControl = m_dataGridContext.DataGridControl; if (dataGridControl != null) { DataGridScrollViewer scrollViewer = dataGridControl.ScrollViewer as DataGridScrollViewer; if (scrollViewer != null) { currentDataGridScrollViewerMeasureVersion = scrollViewer.MeasureVersion; } } this.ColumnStretchingCalculated = true; if (m_dataGridScrollViewerMeasureVersion != currentDataGridScrollViewerMeasureVersion) { // Reset the widthToDistribute since we are in a new pass of measure in the DataGridScrollViewer m_widthToDistribute = widthToDistribute; m_dataGridScrollViewerMeasureVersion = currentDataGridScrollViewerMeasureVersion; } else { if (widthToDistribute >= m_widthToDistribute) { widthToDistribute = m_widthToDistribute; } else { m_widthToDistribute = widthToDistribute; } } List <WorkingColumnWidth> excludedColumns = null; ColumnBase stretchedColumn = null; ReadOnlyObservableCollection <ColumnBase> visibleColumns = m_dataGridContext.VisibleColumns; if (visibleColumns.Count == 0) { return; } switch (columnStretchMode) { case ColumnStretchMode.First: stretchedColumn = visibleColumns[0]; excludedColumns = new List <WorkingColumnWidth>(1); break; case ColumnStretchMode.Last: stretchedColumn = visibleColumns[visibleColumns.Count - 1]; excludedColumns = new List <WorkingColumnWidth>(1); break; case ColumnStretchMode.All: excludedColumns = new List <WorkingColumnWidth>(visibleColumns.Count); foreach (ColumnBase column in visibleColumns) { excludedColumns.Add(new WorkingColumnWidth(column, 1d, columnStretchMinWidth)); } break; case ColumnStretchMode.None: foreach (ColumnBase column in visibleColumns) { if (column.Width.UnitType == ColumnWidthUnitType.Star) { if (excludedColumns == null) { excludedColumns = new List <WorkingColumnWidth>(); } excludedColumns.Add(new WorkingColumnWidth(column, column.Width.Value, columnStretchMinWidth)); } else { column.ClearValue(Column.DesiredWidthProperty); widthToDistribute -= column.ActualWidth; } } break; } if (excludedColumns != null) { if (stretchedColumn != null) { foreach (ColumnBase column in visibleColumns) { if (column == stretchedColumn) { excludedColumns.Add(new WorkingColumnWidth(column, 1, columnStretchMinWidth)); } else { column.ClearValue(Column.DesiredWidthProperty); widthToDistribute -= column.ActualWidth; } } } this.CalculateColumnDesiredWidth(widthToDistribute, excludedColumns, canIncreaseColumnWidth); } }