private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e) { if (this.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { if (this.restoreFocusItemInfo != null) { TreeGridViewItem tgvi = this.ItemContainerGenerator.ContainerFromItem(this.restoreFocusItemInfo) as TreeGridViewItem; if (tgvi != null) { if (this.IsFocused) { tgvi.Focus(); this.restoreFocusItemInfo = null; } } } } }
/// <summary> /// Move focus to parent item /// </summary> /// <param name="childItem">The currently focused item</param> /// <returns>true if succeeds; otherwise false</returns> internal bool FocusToParentItem(TreeGridViewItem childItem) { TreeGridViewItemInfo childInfo = this.ItemContainerGenerator.ItemFromContainer(childItem) as TreeGridViewItemInfo; if (childInfo != null) { var parentInfo = this.GetParentItemInfo(childInfo); if (parentInfo != null) { this.ScrollIntoView(parentInfo); TreeGridViewItem parentContainer = this.ItemContainerGenerator.ContainerFromItem(parentInfo) as TreeGridViewItem; if (parentContainer != null) { return(parentContainer.Focus()); } } } return(false); }