Ejemplo n.º 1
0
        /// <summary>
        /// A virtual function that is called when the selection is changed. Default behavior
        /// is to raise a SelectionChangedEvent
        /// </summary>
        /// <param name="e">The inputs for this event. Can be raised (default behavior) or processed
        ///   in some other way.</param>
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);
            if (IsKeyboardFocusWithin)
            {
                // If keyboard focus is within the control, make sure it is going to the correct place
                TabItem item = GetSelectedTabItem();
                if (item != null)
                {
                    item.SetFocus();
                }
            }
            UpdateSelectedContent();

            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionPatternOnInvalidated) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
            {
                TabControlAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this) as TabControlAutomationPeer;
                if (peer != null)
                {
                    peer.RaiseSelectionEvents(e);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the method that responds to the KeyDown event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            TabItem nextTabItem = null;

            // Handle [Ctrl][Shift]Tab, Home and End cases
            // We have special handling here because if focus is inside the TabItem content we cannot
            // cycle through TabItem because the content is not part of the TabItem visual tree

            int direction  = 0;
            int startIndex = -1;

            switch (e.Key)
            {
            case Key.Tab:
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    startIndex = ItemContainerGenerator.IndexFromContainer(ItemContainerGenerator.ContainerFromItem(SelectedItem));
                    if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        direction = -1;
                    }
                    else
                    {
                        direction = 1;
                    }
                }
                break;

            case Key.Home:
                direction  = 1;
                startIndex = -1;
                break;

            case Key.End:
                direction  = -1;
                startIndex = Items.Count;
                break;
            }

            nextTabItem = FindNextTabItem(startIndex, direction);

            if (nextTabItem != null && nextTabItem != SelectedItem)
            {
                e.Handled = nextTabItem.SetFocus();
            }

            if (!e.Handled)
            {
                base.OnKeyDown(e);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// A virtual function that is called when the selection is changed. Default behavior
        /// is to raise a SelectionChangedEvent
        /// </summary>
        /// <param name="e">The inputs for this event. Can be raised (default behavior) or processed
        ///   in some other way.</param>
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            if (MS.Internal.FrameworkAppContextSwitches.SelectionPropertiesCanLagBehindSelectionChangedEvent)
            {
                // old ("useless") behavior, retained for app-compat
                base.OnSelectionChanged(e);
                if (IsKeyboardFocusWithin)
                {
                    // If keyboard focus is within the control, make sure it is going to the correct place
                    TabItem item = GetSelectedTabItem();
                    if (item != null)
                    {
                        item.SetFocus();
                    }
                }
                UpdateSelectedContent();
            }
            else
            {
                // new behavior (DDVSO 208019) - change SelectedContent and focus
                // before raising SelectionChanged.
                bool isKeyboardFocusWithin = IsKeyboardFocusWithin;

                UpdateSelectedContent();
                if (isKeyboardFocusWithin)
                {
                    // If keyboard focus is within the control, make sure it is going to the correct place
                    TabItem item = GetSelectedTabItem();
                    if (item != null)
                    {
                        item.SetFocus();
                    }
                }
                base.OnSelectionChanged(e);
            }

            if (AutomationPeer.ListenerExists(AutomationEvents.SelectionPatternOnInvalidated) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection) ||
                AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
            {
                TabControlAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(this) as TabControlAutomationPeer;
                if (peer != null)
                {
                    peer.RaiseSelectionEvents(e);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>Provides class handling for the <see cref="E:System.Windows.ContentElement.KeyDown" /> routed event that occurs when the user presses a key.</summary>
        /// <param name="e">Provides data for <see cref="T:System.Windows.Input.KeyEventArgs" />.</param>
        // Token: 0x060056C4 RID: 22212 RVA: 0x0017FF88 File Offset: 0x0017E188
        protected override void OnKeyDown(KeyEventArgs e)
        {
            int direction  = 0;
            int startIndex = -1;
            Key key        = e.Key;

            if (key != Key.Tab)
            {
                if (key != Key.End)
                {
                    if (key == Key.Home)
                    {
                        direction  = 1;
                        startIndex = -1;
                    }
                }
                else
                {
                    direction  = -1;
                    startIndex = base.Items.Count;
                }
            }
            else if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                startIndex = base.ItemContainerGenerator.IndexFromContainer(base.ItemContainerGenerator.ContainerFromItem(base.SelectedItem));
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    direction = -1;
                }
                else
                {
                    direction = 1;
                }
            }
            TabItem tabItem = this.FindNextTabItem(startIndex, direction);

            if (tabItem != null && tabItem != base.SelectedItem)
            {
                e.Handled = tabItem.SetFocus();
            }
            if (!e.Handled)
            {
                base.OnKeyDown(e);
            }
        }
Ejemplo n.º 5
0
 /// <summary>Raises the <see cref="E:System.Windows.Controls.Primitives.Selector.SelectionChanged" /> routed event. </summary>
 /// <param name="e">Provides data for <see cref="T:System.Windows.Controls.SelectionChangedEventArgs" />. </param>
 // Token: 0x060056C2 RID: 22210 RVA: 0x0017FE90 File Offset: 0x0017E090
 protected override void OnSelectionChanged(SelectionChangedEventArgs e)
 {
     if (FrameworkAppContextSwitches.SelectionPropertiesCanLagBehindSelectionChangedEvent)
     {
         base.OnSelectionChanged(e);
         if (base.IsKeyboardFocusWithin)
         {
             TabItem selectedTabItem = this.GetSelectedTabItem();
             if (selectedTabItem != null)
             {
                 selectedTabItem.SetFocus();
             }
         }
         this.UpdateSelectedContent();
     }
     else
     {
         bool isKeyboardFocusWithin = base.IsKeyboardFocusWithin;
         this.UpdateSelectedContent();
         if (isKeyboardFocusWithin)
         {
             TabItem selectedTabItem2 = this.GetSelectedTabItem();
             if (selectedTabItem2 != null)
             {
                 selectedTabItem2.SetFocus();
             }
         }
         base.OnSelectionChanged(e);
     }
     if (AutomationPeer.ListenerExists(AutomationEvents.SelectionPatternOnInvalidated) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
     {
         TabControlAutomationPeer tabControlAutomationPeer = UIElementAutomationPeer.CreatePeerForElement(this) as TabControlAutomationPeer;
         if (tabControlAutomationPeer != null)
         {
             tabControlAutomationPeer.RaiseSelectionEvents(e);
         }
     }
 }