Пример #1
0
        /// <summary>
        /// Gets the generated (UI) EnhancedTreeViewItem.
        /// </summary>
        /// <param name="containerGenerator">The ItemContainerGenerator from the "parent".</param>
        /// <param name="item">The (bound) item to get the generated UI Item.</param>
        /// <returns>The generated UI EnhancedTreeViewItem. null if nothing to return.</returns>
        private static EnhancedTreeViewItem ContainerFromItem(ItemContainerGenerator containerGenerator, object item)
        {
            if (containerGenerator != null)
            {
                var container = containerGenerator.ContainerFromItem(item) as EnhancedTreeViewItem;
                if (container != null)
                {
                    return container;
                }
                // Get items from Container through Reflection. This Property is only public in verision > .NET 4.5
                IEnumerable items = containerGenerator.GetPropertyValue("Items") as IEnumerable;
                if (items != null)
                {
                    foreach (var childItem in items)
                    {
                        var parent = containerGenerator.ContainerFromItem(childItem) as EnhancedTreeViewItem;
                        if (parent == null)
                        {
                            continue;
                        }

                        container = parent.ItemContainerGenerator.ContainerFromItem(item) as EnhancedTreeViewItem;
                        if (container != null)
                        {
                            return container;
                        }

                        container = ContainerFromItem(parent.ItemContainerGenerator, item);
                        if (container != null)
                        {
                            return container;
                        }
                    }
                }
            }
            return null;
        }