protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e) { base.OnPreviewGotKeyboardFocus(e); if (this.AutoSelectBehavior == AutoSelectBehavior.OnFocus) { // If the focus was not in one of our child ( or popup ), we select all the text. if (!TreeHelper.IsDescendantOf(e.OldFocus as DependencyObject, this)) { this.SelectAll(); } } }
/// <summary> /// Returns true if the specified element is a child of parent somewhere in the visual /// tree. This method will work for Visual, FrameworkElement and FrameworkContentElement. /// </summary> /// <param name="element">The element that is potentially a child of the specified parent.</param> /// <param name="parent">The element that is potentially a parent of the specified element.</param> public static bool IsDescendantOf(DependencyObject element, DependencyObject parent) { return(TreeHelper.IsDescendantOf(element, parent, true)); }