Exemple #1
0
        /// <summary>Updates the displayed cells when the <see cref="P:System.Windows.Controls.DataGrid.Columns" /> collection has changed. </summary>
        /// <param name="columns">The <see cref="P:System.Windows.Controls.DataGrid.Columns" /> collection.</param>
        /// <param name="e">The event data from the <see cref="E:System.Collections.ObjectModel.ObservableCollection`1.CollectionChanged" /> event of the <see cref="P:System.Windows.Controls.DataGrid.Columns" /> collection.</param>
        // Token: 0x06005C9C RID: 23708 RVA: 0x001A0DE4 File Offset: 0x0019EFE4
        protected internal virtual void OnColumnsChanged(ObservableCollection <DataGridColumn> columns, NotifyCollectionChangedEventArgs e)
        {
            MultipleCopiesCollection multipleCopiesCollection = base.ItemsSource as MultipleCopiesCollection;

            if (multipleCopiesCollection != null)
            {
                multipleCopiesCollection.MirrorCollectionChange(e);
            }
        }
Exemple #2
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;

            Debug.Assert(dataGridOwner != null, "We shouldn't be syncing properties if we don't have a valid DataGrid owner");

            DataGridHelper.TransferProperty(this, HeightProperty);
            DataGridHelper.TransferProperty(this, MinHeightProperty);
            DataGridHelper.TransferProperty(this, VirtualizingStackPanel.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), NotificationTarget.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;

                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;
                }

                DataGridRow row = DataGridRowOwner;
                for (int i = 0; i < dirtyCount; i++)
                {
                    cell = (DataGridCell)ItemContainerGenerator.ContainerFromIndex(i);
                    if (cell != null)
                    {
                        cell.PrepareCell(row.Item, this, row);
                    }
                }
            }
        }
        /// <summary>
        ///     Notification from the DataGrid that the columns collection has changed.
        /// </summary>
        /// <param name="columns">The columns collection.</param>
        /// <param name="e">The event arguments from the collection's change event.</param>
        protected internal virtual void OnColumnsChanged(ObservableCollection <DataGridColumn> columns, NotifyCollectionChangedEventArgs e)
        {
            // Update the ItemsSource for the cells
            MultipleCopiesCollection cellItems = ItemsSource as MultipleCopiesCollection;

            if (cellItems != null)
            {
                cellItems.MirrorCollectionChange(e);
            }

            // For a reset event the only thing the MultipleCopiesCollection can do is set its count to 0.
            Debug.Assert(
                e.Action != NotifyCollectionChangedAction.Reset || columns.Count == 0,
                "A Reset event should only be fired for a Clear event from the columns collection");
        }
Exemple #4
0
        /// <summary>Updates the displayed cells when the <see cref="P:System.Windows.Controls.Primitives.DataGridCellsPresenter.Item" /> property value has changed. </summary>
        /// <param name="oldItem">The previous value of the <see cref="P:System.Windows.Controls.Primitives.DataGridCellsPresenter.Item" /> property.</param>
        /// <param name="newItem">The new value of the <see cref="P:System.Windows.Controls.Primitives.DataGridCellsPresenter.Item" /> property.</param>
        // Token: 0x06005C96 RID: 23702 RVA: 0x001A0D14 File Offset: 0x0019EF14
        protected virtual void OnItemChanged(object oldItem, object newItem)
        {
            ObservableCollection <DataGridColumn> columns = this.Columns;

            if (columns != null)
            {
                MultipleCopiesCollection multipleCopiesCollection = base.ItemsSource as MultipleCopiesCollection;
                if (multipleCopiesCollection == null)
                {
                    multipleCopiesCollection = new MultipleCopiesCollection(newItem, columns.Count);
                    base.ItemsSource         = multipleCopiesCollection;
                    return;
                }
                multipleCopiesCollection.CopiedItem = newItem;
            }
        }
        /// <summary>
        ///     Called when the value of the Item property changes.
        /// </summary>
        /// <param name="oldItem">The old value of Item.</param>
        /// <param name="newItem">The new value of Item.</param>
        protected virtual void OnItemChanged(object oldItem, object newItem)
        {
            ObservableCollection <DataGridColumn> columns = Columns;

            if (columns != null)
            {
                // Either update or create a collection that will return the row's data item
                // n number of times, where n is the number of columns.
                MultipleCopiesCollection cellItems = ItemsSource as MultipleCopiesCollection;
                if (cellItems == null)
                {
                    cellItems   = new MultipleCopiesCollection(newItem, columns.Count);
                    ItemsSource = cellItems;
                }
                else
                {
                    cellItems.CopiedItem = newItem;
                }
            }
        }
        private void UpdateItemsSource()
        {
            var columns = this.Columns;
            if (columns != null)
            {
                var newItem = this.DataContext;

                var multipleCopiesCollection = base.ItemsSource as MultipleCopiesCollection;
                if (multipleCopiesCollection == null)
                {
                    multipleCopiesCollection = new MultipleCopiesCollection(newItem, columns.Count);
                    base.ItemsSource = multipleCopiesCollection;
                }
                else
                {
                    multipleCopiesCollection.CopiedItem = newItem;
                }
            }
        }
        /// <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, VirtualizingStackPanel.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), NotificationTarget.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;

                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;
                }

                DataGridRow row = DataGridRowOwner;
                bool        arrangeInvalidated = false;

                // 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 (!arrangeInvalidated && !DoubleUtil.AreClose(cell.ActualWidth, columns[i].Width.DisplayValue))
                        {
                            InvalidateDataGridCellsPanelMeasureAndArrange();
                            arrangeInvalidated = true;
                        }
                    }
                }

                // Keep searching for the mismatch between cell.ActualWidth
                // and Column.Width.DisplayValue
                if (!arrangeInvalidated)
                {
                    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();
                                arrangeInvalidated = true;
                                break;
                            }
                        }
                    }
                }

                if (!arrangeInvalidated && InvalidateCellsPanelOnColumnChange())
                {
                    InvalidateDataGridCellsPanelMeasureAndArrange();
                }
            }
        }
        /// <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;
                            }
                        }
                    }
                }
            }
        }
Exemple #9
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;
                        }
                    }
                }
            }
        }