Пример #1
0
        public static void SetFocusToFocusScope(IInputElement newFocus)
        {
            UIElement newElementFocus = newFocus as UIElement;

            if (newElementFocus != null)
            {
                UIElement focusScope = FocusManager.GetFocusScope(newElementFocus) as UIElement;
                int       priority   = FocusScopeManager.GetFocusScopePriority(focusScope);
                if (priority != FocusScopeManager.DefaultFocusScopePriority)
                {
                    FocusScopeManager.Instance.OnScopeKeyboardFocusChanged(focusScope, priority);
                }
            }
        }
Пример #2
0
        private static void HandlePreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (FocusScopeManager.Instance.ShouldDenyFocusChange)
            {
                e.Handled = true;
                return;
            }

            DependencyObject newFocusObject = e.NewFocus as DependencyObject;

            // if there is a newly focused object and it is not allowed focus
            if (newFocusObject != null && !FocusScopeManager.GetAllowedFocus(newFocusObject))
            {
                // Push focus back to the client's desired focus sink and cancel the change
                // of focus to new focus.
                FocusScopeManager.Instance.ReturnFocus();
                e.Handled = true;
            }
        }
Пример #3
0
 private bool IsFocusScopeManaged(UIElement focusScope, int priority, int priorityStartIndex)
 {
     for (int curScopeIndex = priorityStartIndex; curScopeIndex < this.scopes.Count; curScopeIndex++)
     {
         WeakReference curRef = this.scopes[curScopeIndex];
         if (curRef.IsAlive)
         {
             UIElement curTarget = (UIElement)curRef.Target;
             if (FocusScopeManager.GetFocusScopePriority(curTarget) > priority)
             {
                 return(false);
             }
             if (curTarget == focusScope)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #4
0
        private object CoerceFocusedElement(object newFocus)
        {
            UIElement newFocusElement = newFocus as UIElement;

            if (newFocusElement != null)
            {
                // If we have been told to deny the next focus change then do so
                if (this.ShouldDenyFocusChange)
                {
                    this.EndDenyNextFocusChange();
                    return(DependencyProperty.UnsetValue);
                }

                // Don't allow logical focus to go to elements that are not focusable.
                if (newFocus != null && !FocusScopeManager.GetAllowedFocus(newFocusElement))
                {
                    return(DependencyProperty.UnsetValue);
                }
            }
            return(newFocus);
        }
Пример #5
0
        private int FindStartIndexForPriority(int priority)
        {
            int startIndex = 0;

            for (; startIndex < this.scopes.Count; startIndex++)
            {
                WeakReference curRef = this.scopes[startIndex];
                if (curRef.IsAlive)
                {
                    if (FocusScopeManager.GetFocusScopePriority((UIElement)curRef.Target) >= priority)
                    {
                        break;
                    }
                }
                else
                {
                    this.listContainsDeadReferences = true;
                }
            }

            return(startIndex);
        }