// <summary>
        // Returns a SelectionPath pointing to the first visible category in the list
        // or null if no such category exists.
        // </summary>
        // <param name="categoryList">CategoryList for reference</param>
        // <returns>SelectionPath pointing to the first visible category in the list
        // or null if no such category exists.</returns>
        public SelectionPath GetDefaultSelectionPath(CategoryList categoryList)
        {
            foreach (CategoryEntry categoryEntry in categoryList)
            {
                CategoryContainer container = categoryList.FindCategoryEntryVisual(categoryEntry);
                if (container != null && container.Visibility == Visibility.Visible)
                {
                    return(CategoryContainerSelectionPathInterpreter.Instance.ConstructSelectionPath(categoryEntry.CategoryName, false));
                }
            }

            return(null);
        }
        // ISelectionPathInterpreter Members

        public DependencyObject ResolveSelectionPath(CategoryList root, SelectionPath path, out bool pendingGeneration)
        {
            pendingGeneration = false;
            if (path == null || !string.Equals(PathTypeId, path.PathTypeId))
            {
                Debug.Fail("Invalid SelectionPath specified.");
                return(null);
            }

            if (root == null)
            {
                Debug.Fail("No CategoryList specified.");
                return(null);
            }

            string[] pathValues   = path.Path.Split(',');
            string   categoryName = PersistedStateUtilities.Unescape(pathValues[0]);
            bool     isAdvanced   = pathValues.Length == 2;

            CategoryEntry category = root.FindCategory(categoryName);

            if (category == null)
            {
                return(null);
            }

            DependencyObject categoryVisual = root.FindCategoryEntryVisual(category);

            if (categoryVisual == null)
            {
                return(null);
            }

            DependencyObject searchStart;

            // For basic section, start at the root.
            // For advanced section, start at the advanced expander.
            // The next SelectionStop in both cases will be the section header SelectionStop.
            if (!isAdvanced)
            {
                searchStart = categoryVisual;
            }
            else
            {
                searchStart = VisualTreeUtils.GetNamedChild <FrameworkElement>(categoryVisual, "PART_AdvancedExpander");
            }

            return(PropertySelection.FindNeighborSelectionStop <DependencyObject>(searchStart, SearchDirection.Next));
        }
        // ISelectionPathInterpreter Members

        public DependencyObject ResolveSelectionPath(CategoryList root, SelectionPath path, out bool pendingGeneration) 
        {
            pendingGeneration = false;
            if (path == null || !string.Equals(PathTypeId, path.PathTypeId)) 
            {
                Debug.Fail("Invalid SelectionPath specified.");
                return null;
            }

            if (root == null) 
            {
                Debug.Fail("No CategoryList specified.");
                return null;
            }

            string[] pathValues = path.Path.Split(',');
            string categoryName = PersistedStateUtilities.Unescape(pathValues[0]);
            bool isAdvanced = pathValues.Length == 2;

            CategoryEntry category = root.FindCategory(categoryName);
            if (category == null)
            {
                return null;
            }

            DependencyObject categoryVisual = root.FindCategoryEntryVisual(category);
            if (categoryVisual == null)
            {
                return null;
            }

            DependencyObject searchStart;

            // For basic section, start at the root.
            // For advanced section, start at the advanced expander.
            // The next SelectionStop in both cases will be the section header SelectionStop.
            if (!isAdvanced)
            {
                searchStart = categoryVisual;
            }
            else
            {
                searchStart = VisualTreeUtils.GetNamedChild<FrameworkElement>(categoryVisual, "PART_AdvancedExpander");
            }

            return PropertySelection.FindNeighborSelectionStop<DependencyObject>(searchStart, SearchDirection.Next);
        }
        // <summary>
        // Returns a SelectionPath pointing to the first visible category in the list
        // or null if no such category exists.
        // </summary>
        // <param name="categoryList">CategoryList for reference</param>
        // <returns>SelectionPath pointing to the first visible category in the list
        // or null if no such category exists.</returns>
        public SelectionPath GetDefaultSelectionPath(CategoryList categoryList) 
        {
            foreach (CategoryEntry categoryEntry in categoryList) 
            {
                CategoryContainer container = categoryList.FindCategoryEntryVisual(categoryEntry);
                if (container != null && container.Visibility == Visibility.Visible) 
                {
                    return CategoryContainerSelectionPathInterpreter.Instance.ConstructSelectionPath(categoryEntry.CategoryName, false);
                }
            }

            return null;
        }