/// <summary>Responds to a change to the <see cref="P:System.Windows.UIElement.IsKeyboardFocusWithin" /> property. </summary>
 /// <param name="e">The event data for the <see cref="E:System.Windows.UIElement.IsKeyboardFocusWithinChanged" /> event.</param>
 // Token: 0x06005E77 RID: 24183 RVA: 0x001A7898 File Offset: 0x001A5A98
 protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
 {
     base.OnIsKeyboardFocusWithinChanged(e);
     if (base.IsKeyboardFocusWithin)
     {
         if (!this.IsMenuMode)
         {
             this.IsMenuMode       = true;
             this.OpenOnMouseEnter = false;
         }
         if (KeyboardNavigation.IsKeyboardMostRecentInputDevice())
         {
             KeyboardNavigation.EnableKeyboardCues(this, true);
         }
     }
     else
     {
         KeyboardNavigation.EnableKeyboardCues(this, false);
         if (this.IsMenuMode)
         {
             if (this.HasCapture)
             {
                 this.IsMenuMode = false;
             }
         }
         else if (this.CurrentSelection != null)
         {
             this.CurrentSelection = null;
         }
     }
     this.InvokeMenuOpenedClosedAutomationEvent(base.IsKeyboardFocusWithin);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the focus is no longer on or within this element.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnIsKeyboardFocusWithinChanged(e);

            if (IsKeyboardFocusWithin)
            {
                // When focus enters the menu, we should enter menu mode.
                if (!IsMenuMode)
                {
                    IsMenuMode       = true;
                    OpenOnMouseEnter = false;
                }

                if (KeyboardNavigation.IsKeyboardMostRecentInputDevice())
                {
                    // Turn on keyboard cues b/c we took focus with the keyboard
                    KeyboardNavigation.EnableKeyboardCues(this, true);
                }
            }
            else
            {
                // Turn off keyboard cues
                KeyboardNavigation.EnableKeyboardCues(this, false);

                if (IsMenuMode)
                {
                    // When showing a ContextMenu of a MenuItem, the ContextMenu will take focus
                    // out of this menu's subtree.  The ContextMenu takes capture before taking
                    // focus, so if we are in MenuMode but don't have capture then we are waiting
                    // for the context menu to close.  Thus, we should only exit menu mode when
                    // we have capture.
                    if (HasCapture)
                    {
                        IsMenuMode = false;
                    }
                }
                else
                {
                    // Okay, we weren't in menu mode but we could have had a selection (mouse hovering), so clear that
                    if (CurrentSelection != null)
                    {
                        CurrentSelection = null;
                    }
                }
            }

            InvokeMenuOpenedClosedAutomationEvent(IsKeyboardFocusWithin);
        }