protected override List <AutomationPeer> GetChildrenCore()
        {
            ListBox lb = OwnerListTimePickerPopup.ListBoxPart;

            if (lb != null)
            {
                // if possible, delegate to ListBox.
                ListBoxAutomationPeer peer = (ListBoxAutomationPeer)CreatePeerForElement(lb);
                return(peer.GetChildren());
            }
            else
            {
                return(base.GetChildrenCore());
            }
        }
        /// <summary>
        /// Retrieves a UI Automation provider for each child element that is
        /// selected.
        /// </summary>
        /// <returns>An array of UI Automation providers.</returns>
        public IRawElementProviderSimple[] GetSelection()
        {
            ListBox lb = OwnerListTimePickerPopup.ListBoxPart;

            if (lb != null)
            {
                object selectedItem = lb.SelectedItem;
                if (selectedItem != null)
                {
                    AutomationPeer peer = null;
                    // check if the selecteditem is an UIElement
                    UIElement uie = selectedItem as UIElement;
                    if (uie != null)
                    {
                        peer = CreatePeerForElement(uie);
                    }
                    else
                    {
                        ListBoxAutomationPeer lbpeer = CreatePeerForElement(lb) as ListBoxAutomationPeer;
                        if (lbpeer != null)
                        {
                            List <AutomationPeer> children = lbpeer.GetChildren();
                            if (children != null)
                            {
                                peer = children.FirstOrDefault(child =>
                                {
                                    // ISelectionItemProvider.IsSelected does not yet give the correct information
                                    ListBoxItemAutomationPeer listboxitemPeer = child as ListBoxItemAutomationPeer;
                                    if (listboxitemPeer != null)
                                    {
                                        ListBoxItem item = listboxitemPeer.Owner as ListBoxItem;
                                        return(item != null && item.DataContext.Equals(selectedItem));
                                    }
                                    return(false);
                                });
                            }
                        }
                    }

                    // we only ever expect to return an array of one peer.
                    if (peer != null)
                    {
                        return(new[] { ProviderFromPeer(peer) });
                    }
                }
            }
            return(new IRawElementProviderSimple[] { });
        }