Ejemplo n.º 1
0
        private void OnScopeKeyboardFocusChanged(UIElement focusScope, int priority)
        {
            switch (this.ActivateBehavior)
            {
            case FocusScopeManagerActivateBehavior.ClearFocusedElementInLowerPriorityScopes:
                if (focusScope == this.ActiveManagedFocusScope)
                {
                    break;
                }
                int indexForPriority = this.FindStartIndexForPriority(priority);
                if (!this.IsFocusScopeManaged(focusScope, priority, indexForPriority))
                {
                    break;
                }
                for (int index = indexForPriority; index < this.scopes.Count; ++index)
                {
                    WeakReference weakReference = this.scopes[index];
                    if (weakReference.IsAlive)
                    {
                        UIElement uiElement = (UIElement)weakReference.Target;
                        if (uiElement != focusScope)
                        {
                            FocusManager.SetFocusedElement((DependencyObject)uiElement, (IInputElement)null);
                        }
                    }
                    else
                    {
                        this.listContainsDeadReferences = true;
                    }
                }
                this.CleanUpDeadReferences();
                this.ActiveManagedFocusScope = focusScope;
                break;

            case FocusScopeManagerActivateBehavior.UpdateFocusedElementInAncestorFocusScopes:
                DependencyObject element = (DependencyObject)focusScope;
                while (true)
                {
                    DependencyObject parentFocusScope = FocusScopeManager.GetParentFocusScope(element);
                    if (parentFocusScope != null)
                    {
                        FocusManager.SetFocusedElement(parentFocusScope, (IInputElement)element);
                        element = parentFocusScope;
                    }
                    else
                    {
                        break;
                    }
                }
                break;
            }
        }
Ejemplo n.º 2
0
        public static void SetFocusToFocusScope(IInputElement newFocus)
        {
            UIElement uiElement = newFocus as UIElement;

            if (uiElement == null)
            {
                return;
            }
            UIElement focusScope         = FocusManager.GetFocusScope((DependencyObject)uiElement) as UIElement;
            int       focusScopePriority = FocusScopeManager.GetFocusScopePriority((DependencyObject)focusScope);

            if (focusScopePriority == FocusScopeManager.DefaultFocusScopePriority)
            {
                return;
            }
            FocusScopeManager.Instance.OnScopeKeyboardFocusChanged(focusScope, focusScopePriority);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 private bool IsFocusScopeManaged(UIElement focusScope, int priority, int priorityStartIndex)
 {
     for (int index = priorityStartIndex; index < this.scopes.Count; ++index)
     {
         WeakReference weakReference = this.scopes[index];
         if (weakReference.IsAlive)
         {
             UIElement uiElement = (UIElement)weakReference.Target;
             if (FocusScopeManager.GetFocusScopePriority((DependencyObject)uiElement) > priority)
             {
                 return(false);
             }
             if (uiElement == focusScope)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        private int FindStartIndexForPriority(int priority)
        {
            int index;

            for (index = 0; index < this.scopes.Count; ++index)
            {
                WeakReference weakReference = this.scopes[index];
                if (weakReference.IsAlive)
                {
                    if (FocusScopeManager.GetFocusScopePriority((DependencyObject)weakReference.Target) >= priority)
                    {
                        break;
                    }
                }
                else
                {
                    this.listContainsDeadReferences = true;
                }
            }
            return(index);
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
 private static void HandleGotKeyboardFocusEvent(object sender, KeyboardFocusChangedEventArgs e)
 {
     FocusScopeManager.SetFocusToFocusScope(e.NewFocus);
 }