/// <summary>
        ///     Tells the row owner about this element.
        /// </summary>
        public override void OnApplyTemplate()
        {
            // If a new template has just been generated then 
            // be sure to clear any stale ItemsHost references
            if (InternalItemsHost != null && !this.IsAncestorOf(InternalItemsHost))
            {
                InternalItemsHost = null;
            }
            
            base.OnApplyTemplate();

            // Find the columns collection and set the ItemsSource.
            DataGrid grid = ParentDataGrid;

            if (grid != null)
            {
                ItemsSource = new DataGridColumnHeaderCollection(grid.Columns);
                grid.ColumnHeadersPresenter = this;
                DataGridHelper.TransferProperty(this, VirtualizingPanel.IsVirtualizingProperty);

                DataGridColumnHeader fillerColumnHeader = GetTemplateChild(ElementFillerColumnHeader) as DataGridColumnHeader;
                if (fillerColumnHeader != null)
                {
                    DataGridHelper.TransferProperty(fillerColumnHeader, DataGridColumnHeader.StyleProperty);
                    DataGridHelper.TransferProperty(fillerColumnHeader, DataGridColumnHeader.HeightProperty);
                }
            }
            else
            {
                ItemsSource = null;
            }
        }
        /// <summary>
        ///     Tells the row owner about this element.
        /// </summary> 
        public override void OnApplyTemplate()
        { 
            base.OnApplyTemplate(); 

            // Find the columns collection and set the ItemsSource. 
            DataGrid grid = ParentDataGrid;

            if (grid != null)
            { 
                ItemsSource = new DataGridColumnHeaderCollection(grid.Columns);
                grid.ColumnHeadersPresenter = this; 
                DataGridHelper.TransferProperty(this, VirtualizingStackPanel.IsVirtualizingProperty); 

                DataGridColumnHeader fillerColumnHeader = GetTemplateChild(ElementFillerColumnHeader) as DataGridColumnHeader; 
                if (fillerColumnHeader != null)
                {
                    DataGridHelper.TransferProperty(fillerColumnHeader, DataGridColumnHeader.StyleProperty);
                    DataGridHelper.TransferProperty(fillerColumnHeader, DataGridColumnHeader.HeightProperty); 
                }
            } 
            else 
            {
                ItemsSource = null; 
            }
        }
        // Token: 0x06004889 RID: 18569 RVA: 0x00149CA0 File Offset: 0x00147EA0
        private void OnColumnsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            NotifyCollectionChangedEventArgs args;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                args = new NotifyCollectionChangedEventArgs(e.Action, DataGridColumnHeaderCollection.HeadersFromColumns(e.NewItems), e.NewStartingIndex);
                break;

            case NotifyCollectionChangedAction.Remove:
                args = new NotifyCollectionChangedEventArgs(e.Action, DataGridColumnHeaderCollection.HeadersFromColumns(e.OldItems), e.OldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Replace:
                args = new NotifyCollectionChangedEventArgs(e.Action, DataGridColumnHeaderCollection.HeadersFromColumns(e.NewItems), DataGridColumnHeaderCollection.HeadersFromColumns(e.OldItems), e.OldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Move:
                args = new NotifyCollectionChangedEventArgs(e.Action, DataGridColumnHeaderCollection.HeadersFromColumns(e.OldItems), e.NewStartingIndex, e.OldStartingIndex);
                break;

            default:
                args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
                break;
            }
            this.FireCollectionChanged(args);
        }