Exemplo n.º 1
0
        /// <summary>
        ///     Update all properties that get a value from the DataGrid
        /// </summary>
        /// <remarks>
        ///     See comment on DataGridRow.SyncProperties
        /// </remarks>
        internal void SyncProperties(bool forcePrepareCells)
        {
            var dataGridOwner = DataGridOwner;

            if (dataGridOwner == null)
            {
                return;
            }

            DataGridHelper.TransferProperty(this, HeightProperty);
            DataGridHelper.TransferProperty(this, MinHeightProperty);
            DataGridHelper.TransferProperty(this, VirtualizingPanel.IsVirtualizingProperty);

            // This is a convenient way to walk through all cells and force them to call CoerceValue(StyleProperty)
            NotifyPropertyChanged(this, new DependencyPropertyChangedEventArgs(DataGrid.CellStyleProperty, null, null), DataGridNotificationTarget.Cells);

            // We may have missed an Add / Remove of a column from the grid (DataGridRow.OnColumnsChanged)
            // Sync the MultipleCopiesCollection count and update the Column on changed cells
            MultipleCopiesCollection cellItems = ItemsSource as MultipleCopiesCollection;

            if (cellItems != null)
            {
                DataGridCell cell;
                ObservableCollection <DataGridColumn> columns = dataGridOwner.Columns;
                int  newColumnCount = columns.Count;
                int  oldColumnCount = cellItems.Count;
                int  dirtyCount     = 0;
                bool measureAndArrangeInvalidated = false;

                if (newColumnCount != oldColumnCount)
                {
                    cellItems.SyncToCount(newColumnCount);

                    // Newly added or removed containers will be updated by the generator via PrepareContainer.
                    // All others may have a different column
                    dirtyCount = Math.Min(newColumnCount, oldColumnCount);
                }
                else if (forcePrepareCells)
                {
                    dirtyCount = newColumnCount;
                }

                // if the DataGridCellsPanel missed out on some column virtualization
                // activity while the row was virtualized, it needs to be measured
                DataGridCellsPanel cellsPanel = InternalItemsHost as DataGridCellsPanel;
                if (cellsPanel != null)
                {
                    if (cellsPanel.HasCorrectRealizedColumns)
                    {
                        // This operation is performed when a DataGridRow is being prepared. So if we are working
                        // with a recycled DataGridRow we need to make sure to re-arrange it so that it picks up the
                        // correct CellsPanelHorizontalOffset. See Dev11 170908.
                        cellsPanel.InvalidateArrange();
                    }
                    else
                    {
                        InvalidateDataGridCellsPanelMeasureAndArrange();
                        measureAndArrangeInvalidated = true;
                    }
                }

                DataGridRow row = DataGridRowOwner;

                // Prepare the cells until dirtyCount is reached. Also invalidate the cells panel's measure
                // and arrange if there is a mismatch between cell.ActualWidth and Column.Width.DisplayValue
                for (int i = 0; i < dirtyCount; i++)
                {
                    cell = (DataGridCell)ItemContainerGenerator.ContainerFromIndex(i);
                    if (cell != null)
                    {
                        cell.PrepareCell(row.Item, this, row);
                        if (!measureAndArrangeInvalidated && !DoubleUtil.AreClose(cell.ActualWidth, columns[i].Width.DisplayValue))
                        {
                            InvalidateDataGridCellsPanelMeasureAndArrange();
                            measureAndArrangeInvalidated = true;
                        }
                    }
                }

                // Keep searching for the mismatch between cell.ActualWidth
                // and Column.Width.DisplayValue
                if (!measureAndArrangeInvalidated)
                {
                    for (int i = dirtyCount; i < newColumnCount; i++)
                    {
                        cell = (DataGridCell)ItemContainerGenerator.ContainerFromIndex(i);
                        if (cell != null)
                        {
                            if (!DoubleUtil.AreClose(cell.ActualWidth, columns[i].Width.DisplayValue))
                            {
                                InvalidateDataGridCellsPanelMeasureAndArrange();
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Token: 0x06005C91 RID: 23697 RVA: 0x001A0AF0 File Offset: 0x0019ECF0
        internal void SyncProperties(bool forcePrepareCells)
        {
            DataGrid dataGridOwner = this.DataGridOwner;

            if (dataGridOwner == null)
            {
                return;
            }
            DataGridHelper.TransferProperty(this, FrameworkElement.HeightProperty);
            DataGridHelper.TransferProperty(this, FrameworkElement.MinHeightProperty);
            DataGridHelper.TransferProperty(this, VirtualizingPanel.IsVirtualizingProperty);
            this.NotifyPropertyChanged(this, new DependencyPropertyChangedEventArgs(DataGrid.CellStyleProperty, null, null), DataGridNotificationTarget.Cells);
            MultipleCopiesCollection multipleCopiesCollection = base.ItemsSource as MultipleCopiesCollection;

            if (multipleCopiesCollection != null)
            {
                ObservableCollection <DataGridColumn> columns = dataGridOwner.Columns;
                int  count  = columns.Count;
                int  count2 = multipleCopiesCollection.Count;
                int  num    = 0;
                bool flag   = false;
                if (count != count2)
                {
                    multipleCopiesCollection.SyncToCount(count);
                    num = Math.Min(count, count2);
                }
                else if (forcePrepareCells)
                {
                    num = count;
                }
                DataGridCellsPanel dataGridCellsPanel = this.InternalItemsHost as DataGridCellsPanel;
                if (dataGridCellsPanel != null)
                {
                    if (dataGridCellsPanel.HasCorrectRealizedColumns)
                    {
                        dataGridCellsPanel.InvalidateArrange();
                    }
                    else
                    {
                        this.InvalidateDataGridCellsPanelMeasureAndArrange();
                        flag = true;
                    }
                }
                DataGridRow dataGridRowOwner = this.DataGridRowOwner;
                for (int i = 0; i < num; i++)
                {
                    DataGridCell dataGridCell = (DataGridCell)base.ItemContainerGenerator.ContainerFromIndex(i);
                    if (dataGridCell != null)
                    {
                        dataGridCell.PrepareCell(dataGridRowOwner.Item, this, dataGridRowOwner);
                        if (!flag && !DoubleUtil.AreClose(dataGridCell.ActualWidth, columns[i].Width.DisplayValue))
                        {
                            this.InvalidateDataGridCellsPanelMeasureAndArrange();
                            flag = true;
                        }
                    }
                }
                if (!flag)
                {
                    for (int j = num; j < count; j++)
                    {
                        DataGridCell dataGridCell = (DataGridCell)base.ItemContainerGenerator.ContainerFromIndex(j);
                        if (dataGridCell != null && !DoubleUtil.AreClose(dataGridCell.ActualWidth, columns[j].Width.DisplayValue))
                        {
                            this.InvalidateDataGridCellsPanelMeasureAndArrange();
                            return;
                        }
                    }
                }
            }
        }