Exemplo n.º 1
0
 void SetAllExpandState(bool p_isExpanded)
 {
     foreach (var item in RootItems.GetAllItems())
     {
         item.SetExpandState(p_isExpanded);
     }
     RootItems.Invalidate();
 }
Exemplo n.º 2
0
        /// <summary>
        /// 触发加载子节点事件
        /// </summary>
        /// <param name="p_item"></param>
        /// <returns></returns>
        internal async Task OnLoadingChild(TvItem p_item)
        {
            if (LoadingChild == null)
            {
                return;
            }

            var args = new LoadingChildArgs(p_item);

            LoadingChild(this, args);
            await args.EnsureAllCompleted();

            if (args.Children != null)
            {
                foreach (var item in args.Children)
                {
                    TvItem ti = new TvItem(this, item, p_item);
                    ti.ExpandedState = TvItemExpandedState.NotExpanded;
                    p_item.Children.Add(ti);
                }
                RootItems.Invalidate();
            }
            p_item.HasLoadedChildren = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 删除数据对应的节点,若节点为选择状态,则删除后选择同层后一节点或父节点
        /// </summary>
        /// <param name="p_item"></param>
        public void DeleteItem(object p_item)
        {
            var item = (from row in RootItems.GetAllItems()
                        where row.Data == p_item
                        select row).FirstOrDefault();

            if (item == null)
            {
                return;
            }

            int index;

            if (item.Parent == null)
            {
                index = RootItems.IndexOf(item);
                if (index > -1)
                {
                    RootItems.RemoveAt(index);
                    if ((bool)item.IsSelected)
                    {
                        if (index < RootItems.Count)
                        {
                            SelectedItem = RootItems[index].Data;
                        }
                        else if (RootItems.Count > 0)
                        {
                            SelectedItem = RootItems[RootItems.Count - 1].Data;
                        }
                        else
                        {
                            SelectedItem = null;
                        }
                    }
                }
            }
            else
            {
                var ls = item.Parent.Children;
                index = ls.IndexOf(item);
                if (index > -1)
                {
                    ls.RemoveAt(index);
                    if ((bool)item.IsSelected)
                    {
                        if (index < ls.Count)
                        {
                            SelectedItem = ls[index].Data;
                        }
                        else if (ls.Count > 0)
                        {
                            SelectedItem = ls[ls.Count - 1].Data;
                        }
                        else
                        {
                            SelectedItem = item.Parent.Data;
                        }
                    }
                }
            }
            RootItems.Invalidate();
        }