/// <summary> /// 子类在 Measure 时,调用此方法来连接到 TreeGrid,并同步一些必要的属性。 /// </summary> internal void ConnectToGrid() { if (_treeGrid == null) { _treeGrid = this.GetVisualParent<TreeGrid>(); if (_treeGrid != null) { _columns = _treeGrid.Columns; InternalCollectionChangedEventManager.AddListener(_columns, this); } } }
internal TreeGridSelectionModel(TreeGrid owner, bool isChecking) { this.Owner = owner; this.SelectedItems = new SelectedItemsAPI { _model = this }; this.IsChecking = isChecking; }
protected override void OnIsItemsHostChanged(bool oldIsItemsHost, bool newIsItemsHost) { base.OnIsItemsHostChanged(oldIsItemsHost, newIsItemsHost); if (newIsItemsHost) { var owner = this.TreeGrid; if (owner != null) { IItemContainerGenerator itemContainerGenerator = owner.ItemContainerGenerator; if (itemContainerGenerator != null && itemContainerGenerator == itemContainerGenerator.GetItemContainerGeneratorForPanel(this)) { owner.RowsPanel = this; return; } } } else { if (this._owner != null && this._owner.RowsPanel == this) { this._owner.RowsPanel = null; } this._owner = null; } }
//protected override void ClearContainerForItemOverride(DependencyObject element, object item) //{ // var cell = element as TreeGridCell; // base.ClearContainerForItemOverride(element, item); // this.ReserveEditingContent(cell); //} //private void ReserveEditingContent(TreeGridCell cell) //{ // //IsEditing:把编辑控件存储下来。 // var row = this.Row; // if (row != null) // { // var grid = row.TreeGrid; // if (grid != null && this.DataContext == grid.EditingItem) // { // //非回收模式下,需要把 // if (!grid.IsRecycleMode) // { // if (grid.EditingMode == TreeGridEditingMode.Row || cell.Column == grid.EditingColumn) // { // if (this._editingElements == null) // { // this._editingElements = new Dictionary<TreeGridColumn, UIElement>(); // } // this._editingElements[cell.Column] = cell.Content as UIElement; // } // } // } // } //} private void RestoreEditingContent(TreeGridCell cell, TreeGridColumn column, TreeGrid grid) { ////非回收模式下,为了返回原来的焦点,需要使用之前的编辑控件。 //if (!grid.IsRecycleMode) //{ // //如果之前已经生成了编辑控件,则使用老的控件,这样可以继续之前的编辑信息。 // if (this._editingElements != null) // { // UIElement content = null; // if (this._editingElements.TryGetValue(column, out content)) // { // cell.UpdateContent(content); // //column.PrepareElementForEdit(content as FrameworkElement, null); // //var res = content.Focus(); // //Debug.WriteLine(" content.IsVisible:" + content.IsVisible // // + " content.Focus():" + res // // + " KeyboardFocus:" + Keyboard.FocusedElement.GetType().FullName // // ); // this._editingElements.Remove(column); // } // } //} }
/// <summary> /// 使用此方法可以把当前 View 的控件替换为所给的控件。 /// <remarks> /// 使用场景:如果期望完全使用全新的表格控件,可以使用这个方法来重新设置视图与控件的绑定。 /// 例如:要实现动态列需求时,需要不断地重新生成表格控件。 /// </remarks> /// </summary> /// <param name="treeGrid"></param> public void ReplaceControl(TreeGrid treeGrid) { var oldControl = this.Control; oldControl.ReplaceInParent(treeGrid); if (oldControl.ContextMenu != null) { treeGrid.ContextMenu = oldControl.ContextMenu; } _listEditor.SetControl(treeGrid); this.SetControl(treeGrid); _listEditor.NotifyContextDataChanged(); }
/// <summary> /// Creates the monitor with the tree to be processed. /// </summary> /// <param name="tree">The tree that renders the monitored /// items.</param> /// <exception cref="ArgumentNullException">If <paramref name="tree"/> /// is a null reference.</exception> public ItemMonitor(TreeGrid tree) { if (tree == null) throw new ArgumentNullException("tree"); this.tree = tree; }
/// <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; }
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; } }