protected virtual bool OnReceiveWeakEvent(Type managerType, object sender, EventArgs e)
        {
            var detach = false;

            if (managerType == typeof(PropertyChangedEventManager))
            {
                if (sender == m_dataGridContext)
                {
                    this.OnDataGridContextPropertyChanged(( PropertyChangedEventArgs )e);
                }
            }
            else if (managerType == typeof(ColumnsLayoutChangingEventManager))
            {
                this.OnColumnsLayoutChanging();
            }
            else if (managerType == typeof(ColumnsLayoutChangedEventManager))
            {
                this.OnColumnsLayoutChanged();
            }
            else if (managerType == typeof(ViewChangedEventManager))
            {
                this.OnDataGridControlViewChanged();
                detach = true;
            }
            else if (managerType == typeof(ThemeChangedEventManager))
            {
                this.OnDataGridControlThemeChanged();
                detach = true;
            }
            else if (managerType == typeof(ItemsSourceChangeCompletedEventManager))
            {
                this.OnDataGridControlItemsSourceChanged();
                detach = true;
            }
            else
            {
                return(false);
            }

            if (detach && (m_dataGridContext != null))
            {
                // Detach the ColumnVirtualizationManager from the DataGridContext and detach from the DataGridContext
                ColumnVirtualizationManager.SetColumnVirtualizationManager(m_dataGridContext, null);

                this.Uninitialize();
            }

            return(true);
        }
        public ColumnVirtualizationManager(DataGridContext dataGridContext)
        {
            Debug.Assert(dataGridContext != null);
            m_dataGridContext = dataGridContext;

            // Assign the ColumnVirtualizationManager to the DataGridContext
            ColumnVirtualizationManager.SetColumnVirtualizationManager(m_dataGridContext, this);

            this.Initialize();

            unchecked
            {
                m_version++;
            }
        }
        protected virtual bool OnReceivedWeakEvent(Type managerType, object sender, EventArgs e)
        {
            bool handled = false;
            bool detachFromDataGridContext = false;

            if (managerType == typeof(VisibleColumnsUpdatedEventManager))
            {
                this.IncrementVersion(null);

                handled = true;
            }
            else if (managerType == typeof(ViewChangedEventManager))
            {
                detachFromDataGridContext = true;
                this.IncrementVersion(null);

                handled = true;
            }
            else if (managerType == typeof(ThemeChangedEventManager))
            {
                detachFromDataGridContext = true;
                this.IncrementVersion(null);

                handled = true;
            }
            else if (managerType == typeof(ItemsSourceChangeCompletedEventManager))
            {
                detachFromDataGridContext = true;
                handled = true;
            }

            if (detachFromDataGridContext == true)
            {
                if (m_dataGridContext != null)
                {
                    // Detach the ColumnVirtualizationManager from the DataGridContext and detach from the DataGridContext
                    ColumnVirtualizationManager.SetColumnVirtualizationManager(m_dataGridContext, null);

                    this.Uninitialize();
                }
            }

            return(handled);
        }
        protected override bool OnReceivedWeakEvent(Type managerType, object sender, EventArgs e)
        {
            bool handled = false;
            bool detachFromDataGridContext = false;

            if (managerType == typeof(VisibleColumnsUpdatedEventManager))
            {
                this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.ColumnReordering));

                handled = true;
            }
            else if (managerType == typeof(CollectionChangedEventManager))
            {
                if (sender == this.DataGridContext.Items.SortDescriptions)
                {
                    this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.SortingChanged));
                }

                if (sender == this.DataGridContext.Items.GroupDescriptions)
                {
                    this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.GroupingChanged));
                }

                handled = true;
            }
            else if (managerType == typeof(ColumnActualWidthEventManager))
            {
                ColumnActualWidthChangedEventArgs args = e as ColumnActualWidthChangedEventArgs;

                // We pass the delta between the old and new value to tell the Panel to reduce the
                // horizontal offset when a column is auto-resized to a smaller value
                if (args != null)
                {
                    double delta = args.OldValue - args.NewValue;
                    this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.ColumnActualWidthChanged, delta));
                }
                else
                {
                    this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.ColumnActualWidthChanged));
                }

                handled = true;
            }
            else if (managerType == typeof(ViewChangedEventManager))
            {
                detachFromDataGridContext = true;
                this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.Unspecified));

                handled = true;
            }
            else if (managerType == typeof(ThemeChangedEventManager))
            {
                detachFromDataGridContext = true;
                this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.Unspecified));

                handled = true;
            }
            else if (managerType == typeof(DataGridControlTemplateChangedEventManager))
            {
                this.UpdateScrollViewer();
                this.IncrementVersion(new UpdateMeasureRequiredEventArgs(UpdateMeasureTriggeredAction.Unspecified));

                handled = true;
            }
            else if (managerType == typeof(ItemsSourceChangeCompletedEventManager))
            {
                detachFromDataGridContext = true;
                handled = true;
            }

            if (detachFromDataGridContext == true)
            {
                if (this.DataGridContext != null)
                {
                    // Detach the ColumnVirtualizationManager from the DataGridContext and detach from the DataGridContext
                    ColumnVirtualizationManager.SetColumnVirtualizationManager(this.DataGridContext, null);

                    this.Uninitialize();
                }
            }

            return(handled);
        }