/// <summary> /// We use this function to get the TabItemAutomationPeer associated with the TabItem /// </summary> /// <param name="item">TabItem that we are seeking to find the AutomationPeer for</param> /// <returns>The TabItemAutomationPeer for the specified TabItem</returns> internal static TabItemAutomationPeer GetTabItemAutomationPeer(TabItem item) { TabControlAutomationPeer tabControlPeer = TabControlAutomationPeer.FromElement(item.TabControlParent) as TabControlAutomationPeer; if (tabControlPeer == null) { tabControlPeer = TabControlAutomationPeer.CreatePeerForElement(item.TabControlParent) as TabControlAutomationPeer; } if (tabControlPeer != null) { List <AutomationPeer> children = tabControlPeer.GetChildren(); if (children != null) { foreach (AutomationPeer peer in children) { TabItemAutomationPeer tabItemPeer = peer as TabItemAutomationPeer; if (tabItemPeer != null && tabItemPeer.Owner == item) { return(tabItemPeer); } } } } return(null); }
/// <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); } } }
/// <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); } } }
public void TabControlAutomationPeerTest() { TabControl tabControl = new TabControl(); TabItem tabItem = new TabItem(); TabControlAutomationPeer peer = ((TabControlAutomationPeer)TabControlAutomationPeer.CreatePeerForElement(tabControl)); ISelectionProvider selector = (ISelectionProvider)peer.GetPattern(PatternInterface.Selection); CreateAsyncTask(tabControl, () => Assert.IsFalse(selector.CanSelectMultiple), () => Assert.IsTrue(selector.IsSelectionRequired), () => Assert.IsNull(selector.GetSelection()), () => tabControl.Items.Add(tabItem), () => Assert.IsNotNull(selector.GetSelection()) ); EnqueueTestComplete(); }
/// <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); } } }
public TabItemExAutomationPeer(object owner, TabControlAutomationPeer tabControlAutomationPeer) : base(owner, tabControlAutomationPeer) { }