Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        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();
        }