Exemplo n.º 1
0
        /// <summary>
        ///     Fired when the Row is attached to the DataGrid.  The scenario here is if the user is scrolling and
        ///     the Row is a recycled container that was just added back to the visual tree.  Properties that rely on a value from
        ///     the Grid should be reevaluated because they may be stale.
        /// </summary>
        /// <remarks>
        ///     Properties can obviously be stale if the DataGrid's value changes while the row is disconnected.  They can also
        ///     be stale for unobvious reasons.
        ///
        ///     For example, the Style property is invalidated when we detect a new Visual parent.  This happens for
        ///     elements in the row (such as the RowHeader) before Prepare is called on the Row.  The coercion callback
        ///     will thus be unable to find the DataGrid and will return the wrong value.
        ///
        ///     There is a potential for perf work here.  If we know a DP isn't invalidated when the visual tree is reconnected
        ///     and we know that the Grid hasn't modified that property then its value is likely fine.  We could also cache whether
        ///     or not the Grid's property is the one that's winning.  If not, no need to redo the coercion.  This notification
        ///     is pretty fast already and thus not worth the work for now.
        /// </remarks>
        private void SyncProperties(bool forcePrepareCells)
        {
            // Coerce all properties on Row that depend on values from the DataGrid
            // Style is ok since it's equivalent to ItemContainerStyle and has already been invalidated.
            DataGridHelper.TransferProperty(this, BackgroundProperty);
            DataGridHelper.TransferProperty(this, HeaderStyleProperty);
            DataGridHelper.TransferProperty(this, HeaderTemplateProperty);
            DataGridHelper.TransferProperty(this, HeaderTemplateSelectorProperty);
            DataGridHelper.TransferProperty(this, ValidationErrorTemplateProperty);
            DataGridHelper.TransferProperty(this, DetailsTemplateProperty);
            DataGridHelper.TransferProperty(this, DetailsTemplateSelectorProperty);
            DataGridHelper.TransferProperty(this, DetailsVisibilityProperty);

            CoerceValue(VisibilityProperty); // Handle NewItemPlaceholder case

            RestoreAttachedItemValue(this, DetailsVisibilityProperty);

            var cellsPresenter = CellsPresenter;

            if (cellsPresenter != null)
            {
                cellsPresenter.SyncProperties(forcePrepareCells);
                RestoreAttachedItemValue(cellsPresenter, DataGridCellsPresenter.HeightProperty);
            }

            if (DetailsPresenter != null)
            {
                DetailsPresenter.SyncProperties();
            }

            if (RowHeader != null)
            {
                RowHeader.SyncProperties();
            }
        }