protected override void OnGotFocus(RoutedEventArgs e) { base.OnGotFocus(e); Action action = () => { if (FocusedElement != null) { _hasChildren = true; FocusedElement.Focus(); } else { //Focus first Focusable Child element of ChildWindow var focusableChild = TreeHelper.FindChild <FrameworkElement>(this.Content as DependencyObject, x => x.Focusable); if (focusableChild != null) { _hasChildren = true; focusableChild.Focus(); } else { _hasChildren = false; } } }; Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, action); }
/// <inheritdoc /> public void Dispose() { try { FocusedElement?.Focus(); } catch (COMException) { } }
protected override void OnGotFocus(RoutedEventArgs e) { Action action = () => { if (FocusedElement != null) { FocusedElement.Focus(); } }; Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, action); }