コード例 #1
0
        /// <summary>
        /// Toggle expand/collapse for the an item at the given index
        /// </summary>
        private bool ExpandCollapse(int itemIndex, ForceExpansion forceExpansion)
        {
            var selectedItem = GetItem(itemIndex);

            if (selectedItem == null)
            {
                return(false);
            }

            // handles a node expansion
            var currentItem = selectedItem as FilteredTypeTreeListItem;

            if (currentItem != null && currentItem.CanExpand)
            {
                string currentItemPathDescriptor = currentItem.PathDescriptor;

                // switch state
                if (forceExpansion != ForceExpansion.Idle)
                {
                    currentItem.IsExpanded = (forceExpansion == ForceExpansion.ForceExpand);
                }
                else
                {
                    currentItem.IsExpanded = !currentItem.IsExpanded;
                }

                // saves expansion state
                if (_savedState.ContainsKey(currentItemPathDescriptor))
                {
                    _savedState[currentItemPathDescriptor] = currentItem.IsExpanded;
                }
                else
                {
                    _savedState.Add(currentItemPathDescriptor, currentItem.IsExpanded);
                }

                ApplyExpansionState();

                return(true);
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Returns the full list of items to be displayed, taking into account expanded items
        /// </summary>
        private List <ListItem> GetExpandedItemsList(List <FilteredTypeTreeListItem> list, ForceExpansion forceExpansion)
        {
            if (list == null)
            {
                return(new List <ListItem>());
            }

            var outList = new List <ListItem>();

            foreach (var item in list)
            {
                outList.Add(item);
                var descriptor = item.PathDescriptor;
                if (item.CanExpand)
                {
                    // force expand/collapse?
                    if (forceExpansion != ForceExpansion.Idle)
                    {
                        if (_savedState.ContainsKey(descriptor))
                        {
                            _savedState[descriptor] = forceExpansion == ForceExpansion.ForceExpand;
                        }
                        else
                        {
                            _savedState.Add(descriptor, forceExpansion == ForceExpansion.ForceExpand);
                        }
                    }

                    // restore the expand state of the item if needed
                    if (_savedState.ContainsKey(descriptor))
                    {
                        item.IsExpanded = _savedState[descriptor];
                    }

                    if (item.IsExpanded)
                    {
                        var children = GetExpandedItemsList(item.GetItemChildren(), forceExpansion);
                        if (children != null)
                        {
                            outList.AddRange(children);
                        }
                    }
                    else if (forceExpansion != ForceExpansion.Idle)
                    {
                        // to also force the savedState of the children node
                        GetExpandedItemsList(item.GetItemChildren(), forceExpansion);
                    }
                }
            }

            return(outList);
        }