Com.Aote.ObjectTools.GeneralObject.Extend C# (CSharp) Method

Extend() private method

private Extend ( ObjectList openedList, string childName ) : int
openedList ObjectList
childName string
return int
        private int Extend(ObjectList openedList, string childName)
        {
            int index = openedList.IndexOf(this);
            ObjectList ol = (ObjectList)this.GetPropertyValue(childName);
            foreach (GeneralObject go in ol)
            {
                //已经在列表里,不重复增加
                if (!openedList.Contains(go))
                {
                    index++;
                    //子对象的层次为当前对象层次+1
                    go.Level = this.Level + 1;
                    openedList.Insert(index, go);
                }
                //如果子为可以展开,递归展开子,下一个展开的孩子要在展开的子后面添加
                if (go.IsOpened)
                {
                    index = go.Extend(openedList, childName);
                }
            }
            return index;
        }

Usage Example

Example #1
0
        private static void OnIsOpenedChanged(DependencyObject dp, DependencyPropertyChangedEventArgs args)
        {
            GeneralObject go = (GeneralObject)dp;

            //如果有展开数据存放的列表,树结构对象根据是否打开状态进行数据切换
            if (go.OpenedList != null)
            {
                if (go.IsOpened)
                {
                    go.Extend(go.OpenedList, go.ChildName);
                }
                else
                {
                    go.Closed(go.OpenedList, go.ChildName);
                }
            }
        }