/// <summary> /// Called when the visual parent of this element changes. /// </summary> /// <param name="oldParent"></param> protected internal override void OnVisualParentChanged(DependencyObject oldParent) { ItemsControl oldItemsControl = null; if (VisualTreeHelper.GetParent(this) == null) { if (IsKeyboardFocusWithin) { // This ListBoxItem had focus but was removed from the tree. // The normal behavior is for focus to become null, but we would rather that // focus go to the parent ListBox. // Use the oldParent to get a reference to the ListBox that this ListBoxItem used to be in. // The oldParent's ItemsOwner should be the ListBox. oldItemsControl = ItemsControl.GetItemsOwner(oldParent); } } base.OnVisualParentChanged(oldParent); // If earlier, we decided to set focus to the old parent ListBox, do it here // after calling base so that the state for IsKeyboardFocusWithin is updated correctly. if (oldItemsControl != null) { oldItemsControl.Focus(); } }
/// <summary>Called when the visual parent of a list box item changes. </summary> /// <param name="oldParent">The previous <see cref="P:System.Windows.FrameworkElement.Parent" /> property of the <see cref="T:System.Windows.Controls.ListBoxItem" />.</param> // Token: 0x06005161 RID: 20833 RVA: 0x0016D16C File Offset: 0x0016B36C protected internal override void OnVisualParentChanged(DependencyObject oldParent) { ItemsControl itemsControl = null; if (VisualTreeHelper.GetParent(this) == null && base.IsKeyboardFocusWithin) { itemsControl = ItemsControl.GetItemsOwner(oldParent); } base.OnVisualParentChanged(oldParent); if (itemsControl != null) { itemsControl.Focus(); } }