// Get either the position or the size of the set for this particular item in the case of left nav.
        // We go through all the items and then we determine if the listviewitem from the left listview can be a navigation view item header
        // or a navigation view item. If it's the former, we just reset the count. If it's the latter, we increment the counter.
        // In case of calculating the position, if this is the NavigationViewItemAutomationPeer we're iterating through we break the loop.
        int GetPositionOrSetCountInLeftNavHelper(AutomationOutput automationOutput)
        {
            int returnValue = 0;

            if (GetParentNavigationView() is { } navview)
            {
                if (navview.LeftNavRepeater() is { } repeater)
                {
                    if (GetParent() is AutomationPeer parent)
                    {
                        if (parent.GetChildren() is { } children)
                        {
                            int  index     = 0;
                            bool itemFound = false;

                            foreach (var child in children)
                            {
                                if (repeater.TryGetElement(index) is { } dependencyObject)
                                {
                                    if (dependencyObject is NavigationViewItemHeader)
                                    {
                                        if (automationOutput == AutomationOutput.Size && itemFound)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            returnValue = 0;
                                        }
                                    }
                                    else if (dependencyObject is NavigationViewItem navviewItem)
                                    {
                                        if (navviewItem.Visibility == Visibility.Visible)
                                        {
                                            returnValue++;

                                            if (FrameworkElementAutomationPeer.FromElement(navviewItem) == (this))
                                            {
                                                if (automationOutput == AutomationOutput.Position)
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    itemFound = true;
                                                }
                                            }
                                        }
                                    }
                                }
                                index++;
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
        // Get either the position or the size of the set for this particular item in the case of top nav (primary/overflow items).
        // Basically, we do the same here as GetPositionOrSetCountInLeftNavHelper without dealing with the listview directly, because
        // TopDataProvider provcides two methods: GetOverflowItems() and GetPrimaryItems(), so we can break the loop (in case of position) by
        // comparing the value of the FrameworkElementAutomationPeer we can get from the item we're iterating through to this object.
        private int GetPositionOrSetCountInTopNavHelper(AutomationOutput automationOutput)
        {
            int  returnValue = 0;
            bool itemFound   = false;

            var parentRepeater = GetParentItemsRepeater();

            if (parentRepeater != null)
            {
                var itemsSourceView = parentRepeater.ItemsSourceView;
                if (itemsSourceView != null)
                {
                    var numberOfElements = itemsSourceView.Count;

                    for (int i = 0; i < numberOfElements; i++)
                    {
                        var child = parentRepeater.TryGetElement(i);
                        if (child != null)
                        {
                            if (child is NavigationViewItemHeader)
                            {
                                if (automationOutput == AutomationOutput.Size && itemFound)
                                {
                                    break;
                                }
                                else
                                {
                                    returnValue = 0;
                                }
                            }

                            else if (child is NavigationViewItem navviewitem)
                            {
                                if (navviewitem.Visibility == Visibility.Visible)
                                {
                                    returnValue++;

                                    if (FrameworkElementAutomationPeer.FromElement(navviewitem) == (NavigationViewItemAutomationPeer)(this))
                                    {
                                        if (automationOutput == AutomationOutput.Position)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            itemFound = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
        // Get either the position or the size of the set for this particular item in the case of top nav (primary/overflow items).
        // Basically, we do the same here as GetPositionOrSetCountInLeftNavHelper without dealing with the listview directly, because
        // TopDataProvider provcides two methods: GetOverflowItems() and GetPrimaryItems(), so we can break the loop (in case of position) by
        // comparing the value of the FrameworkElementAutomationPeer we can get from the item we're iterating through to this object.
        int GetPositionOrSetCountInTopNavHelper(IList navigationViewElements, AutomationOutput automationOutput)
        {
            int returnValue = 0;

            if (GetParentNavigationView() is { } navview)
            {
                bool itemFound = false;

                foreach (var child in navigationViewElements)
                {
                    if (navview.ContainerFromMenuItem(child) is { } childAsNavViewItem)
                    {
                        if (child is NavigationViewItemHeader)
                        {
                            if (automationOutput == AutomationOutput.Size && itemFound)
                            {
                                break;
                            }
                            else
                            {
                                returnValue = 0;
                            }
                        }
                        else if (childAsNavViewItem is NavigationViewItem navviewitem)
                        {
                            if (navviewitem.Visibility == Visibility.Visible)
                            {
                                returnValue++;

                                if (FrameworkElementAutomationPeer.FromElement(navviewitem) == (this))
                                {
                                    if (automationOutput == AutomationOutput.Position)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        itemFound = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }
        // Get either the position or the size of the set for this particular item in the case of left nav.
        // We go through all the items and then we determine if the listviewitem from the left listview can be a navigation view item header
        // or a navigation view item. If it's the former, we just reset the count. If it's the latter, we increment the counter.
        // In case of calculating the position, if this is the NavigationViewItemAutomationPeer we're iterating through we break the loop.
        private int GetPositionOrSetCountInLeftNavHelper(AutomationOutput automationOutput)
        {
            int returnValue = 0;

            var repeater = GetParentItemsRepeater();

            if (repeater != null)
            {
                var parent = FrameworkElementAutomationPeer.CreatePeerForElement(repeater) as AutomationPeer;
                if (parent != null)
                {
                    var children = parent.GetChildren();
                    if (children != null)
                    {
                        int  index     = 0;
                        bool itemFound = false;

                        foreach (var child in children)
                        {
                            var dependencyObject = repeater.TryGetElement(index);
                            if (dependencyObject != null)
                            {
                                if (dependencyObject is NavigationViewItemHeader)
                                {
                                    if (automationOutput == AutomationOutput.Size && itemFound)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        returnValue = 0;
                                    }
                                }

                                else if (dependencyObject is NavigationViewItem navviewItem)
                                {
                                    if (navviewItem.Visibility == Visibility.Visible)
                                    {
                                        returnValue++;

                                        if (FrameworkElementAutomationPeer.FromElement(navviewItem) == (NavigationViewItemAutomationPeer)(this))
                                        {
                                            if (automationOutput == AutomationOutput.Position)
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                itemFound = true;
                                            }
                                        }
                                    }
                                }
                            }
                            index++;
                        }
                    }
                }
            }

            return(returnValue);
        }