private object CoerceFocusedElement(object newFocus)
        {
            UIElement uiElement = newFocus as UIElement;

            if (uiElement != null)
            {
                if (this.ShouldDenyFocusChange)
                {
                    this.EndDenyNextFocusChange();
                    return(DependencyProperty.UnsetValue);
                }
                if (newFocus != null && !FocusScopeManager.GetAllowedFocus((DependencyObject)uiElement))
                {
                    return(DependencyProperty.UnsetValue);
                }
            }
            return(newFocus);
        }
        internal static void HandlePreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            DependencyObject element = e.NewFocus as DependencyObject;
            Visual           visual  = element as Visual;

            if (FocusScopeManager.Instance.ShouldDenyFocusChange)
            {
                FocusScopeManager.Instance.EndDenyNextFocusChange();
                if (!(visual is ExpressionFloatingWindow))
                {
                    e.Handled = true;
                    return;
                }
            }
            if (element == null || FocusScopeManager.GetAllowedFocus(element))
            {
                return;
            }
            FocusScopeManager.Instance.ReturnFocus();
            e.Handled = true;
        }