// Token: 0x06005918 RID: 22808 RVA: 0x00189F90 File Offset: 0x00188190 private void Select(bool selected) { TreeView parentTreeView = this.ParentTreeView; ItemsControl parentItemsControl = this.ParentItemsControl; if (parentTreeView != null && parentItemsControl != null && !parentTreeView.IsSelectionChangeActive) { object itemOrContainerFromContainer = parentItemsControl.GetItemOrContainerFromContainer(this); parentTreeView.ChangeSelection(itemOrContainerFromContainer, this, selected); if (selected && parentTreeView.IsKeyboardFocusWithin && !base.IsKeyboardFocusWithin) { base.Focus(); } } }
/// <summary>Provides class handling for the <see cref="E:System.Windows.Controls.ItemContainerGenerator.ItemsChanged" /> event that occurs when there is a change in the <see cref="P:System.Windows.Controls.ItemsControl.Items" /> collection.</summary> /// <param name="e">The event data.</param> // Token: 0x06005933 RID: 22835 RVA: 0x0018A578 File Offset: 0x00188778 protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Reset: if (this.ContainsSelection) { TreeView parentTreeView = this.ParentTreeView; if (parentTreeView != null && !parentTreeView.IsSelectedContainerHookedUp) { this.ContainsSelection = false; this.Select(true); return; } } break; case NotifyCollectionChangedAction.Replace: if (this.ContainsSelection) { TreeView parentTreeView2 = this.ParentTreeView; if (parentTreeView2 != null) { object selectedItem = parentTreeView2.SelectedItem; if (selectedItem != null && selectedItem.Equals(e.OldItems[0])) { parentTreeView2.ChangeSelection(selectedItem, parentTreeView2.SelectedContainer, false); return; } } } break; default: throw new NotSupportedException(SR.Get("UnexpectedCollectionChangeAction", new object[] { e.Action })); } }
private void Select(bool selected) { TreeView tree = ParentTreeView; ItemsControl parent = ParentItemsControl; if ((tree != null) && (parent != null) && !tree.IsSelectionChangeActive) { // Give the TreeView a reference to this container and its data object data = parent.GetItemOrContainerFromContainer(this); tree.ChangeSelection(data, this, selected); // Making focus of TreeViewItem synchronize with selection if needed. if (selected && tree.IsKeyboardFocusWithin && !IsKeyboardFocusWithin) { Focus(); } } }
/// <summary> /// This method is invoked when the Items property changes. /// </summary> protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Reset: if (ContainsSelection) { TreeView tree = ParentTreeView; if ((tree != null) && !tree.IsSelectedContainerHookedUp) { ContainsSelection = false; Select(true); } } break; case NotifyCollectionChangedAction.Replace: if (ContainsSelection) { TreeView tree = ParentTreeView; if (tree != null) { // When Selected item is replaced - remove the selection // Revisit the condition when we support duplicate items in Items collection: if e.OldItems[0] is the same as selected items we will unselect the selected item object selectedItem = tree.SelectedItem; if ((selectedItem != null) && selectedItem.Equals(e.OldItems[0])) { tree.ChangeSelection(selectedItem, tree.SelectedContainer, false); } } } break; case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Move: break; default: throw new NotSupportedException(SR.Get(SRID.UnexpectedCollectionChangeAction, e.Action)); } }