/// <summary> /// 连接到可视父元素,连接成功,则返回 true。 /// </summary> /// <returns></returns> private bool TryConnect() { if (!this.IsConnected) { this._cellsPresenter = ItemsControl.GetItemsOwner(this) as TreeGridCellsPresenter; if (this._cellsPresenter != null) { this._cellsPresenter.InternalItemsHost = this; var row = this._cellsPresenter.Row; if (row != null) { row.CellsPanel = this; this._treeGrid = row.TreeGrid; if (this._treeGrid != null) { InternalCollectionChangedEventManager.AddListener(this._treeGrid.Columns, this); this._rowsPanel = this._treeGrid.RowsPanel; //分组显示时,RowsPanel 为 null,也不能进行虚拟化操作。 this._isVirtualizing = this._rowsPanel != null && this._treeGrid.IsColumnsVirtualizingEnabled; this._isRecycleMode = this._treeGrid.IsRecycleMode; } } } } return(this.IsConnected); }
/// <summary> /// 子类在 Measure 时,调用此方法来连接到 TreeGrid,并同步一些必要的属性。 /// </summary> internal void ConnectToGrid() { if (_treeGrid == null) { _treeGrid = this.GetVisualParent <TreeGrid>(); if (_treeGrid != null) { _columns = _treeGrid.Columns; InternalCollectionChangedEventManager.AddListener(_columns, this); } } }
private void Disconnect() { if (this.IsConnected) { InternalCollectionChangedEventManager.RemoveListener(this._treeGrid.Columns, this); this._rowsPanel = null; this._treeGrid = null; var row = this._cellsPresenter.Row; if (row != null) { row.CellsPanel = null; } this._cellsPresenter.InternalItemsHost = null; this._cellsPresenter = null; } }