Exemplo n.º 1
0
Arquivo: TabItem.cs Projeto: ash2005/z
        /// <summary>
        /// Focus event handler
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            base.OnPreviewGotKeyboardFocus(e);
            if (!e.Handled && e.NewFocus == this)
            {
                if (!IsSelected && TabControlParent != null)
                {
                    SetCurrentValueInternal(IsSelectedProperty, BooleanBoxes.TrueBox);
                    // If focus moved in result of selection - handle the event to prevent setting focus back on the new item
                    if (e.OldFocus != Keyboard.FocusedElement)
                    {
                        e.Handled = true;
                    }
                    else if (GetBoolField(BoolField.SetFocusOnContent))
                    {
                        TabControl parentTabControl = TabControlParent;
                        if (parentTabControl != null)
                        {
                            // Save the parent and check for null to make sure that SetCurrentValue didn't have a change handler
                            // that removed the TabItem from the tree.
                            ContentPresenter selectedContentPresenter = parentTabControl.SelectedContentPresenter;
                            if (selectedContentPresenter != null)
                            {
                                parentTabControl.UpdateLayout(); // Wait for layout
                                bool success = selectedContentPresenter.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));

                                // If we successfully move focus inside the content then don't set focus to the header
                                if (success)
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary> Announces that the keyboard is focused on this element. </summary>
 /// <param name="e">Keyboard input event arguments.</param>
 // Token: 0x060056DB RID: 22235 RVA: 0x001805E4 File Offset: 0x0017E7E4
 protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
 {
     base.OnPreviewGotKeyboardFocus(e);
     if (!e.Handled && e.NewFocus == this)
     {
         if (FrameworkAppContextSwitches.SelectionPropertiesCanLagBehindSelectionChangedEvent)
         {
             if (!this.IsSelected && this.TabControlParent != null)
             {
                 base.SetCurrentValueInternal(TabItem.IsSelectedProperty, BooleanBoxes.TrueBox);
                 if (e.OldFocus != Keyboard.FocusedElement)
                 {
                     e.Handled = true;
                     return;
                 }
                 if (this.GetBoolField(TabItem.BoolField.SetFocusOnContent))
                 {
                     TabControl tabControlParent = this.TabControlParent;
                     if (tabControlParent != null)
                     {
                         ContentPresenter selectedContentPresenter = tabControlParent.SelectedContentPresenter;
                         if (selectedContentPresenter != null)
                         {
                             tabControlParent.UpdateLayout();
                             bool flag = selectedContentPresenter.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
                             if (flag)
                             {
                                 e.Handled = true;
                                 return;
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             if (!this.IsSelected && this.TabControlParent != null)
             {
                 base.SetCurrentValueInternal(TabItem.IsSelectedProperty, BooleanBoxes.TrueBox);
                 if (e.OldFocus != Keyboard.FocusedElement)
                 {
                     e.Handled = true;
                 }
             }
             if (!e.Handled && this.GetBoolField(TabItem.BoolField.SetFocusOnContent))
             {
                 TabControl tabControlParent2 = this.TabControlParent;
                 if (tabControlParent2 != null)
                 {
                     ContentPresenter selectedContentPresenter2 = tabControlParent2.SelectedContentPresenter;
                     if (selectedContentPresenter2 != null)
                     {
                         tabControlParent2.UpdateLayout();
                         bool flag2 = selectedContentPresenter2.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
                         if (flag2)
                         {
                             e.Handled = true;
                         }
                     }
                 }
             }
         }
     }
 }