/// <summary> /// 将子节点移动到新的索引位置。 /// </summary> /// <param name="newIndex">新的索引位置</param> /// <param name="child">要移动位置的子节点</param> /// <returns>成功与否?</returns> public virtual bool MoveChild(int newIndex, ViNamedObject child) { if (this.Owner != null) { if (child.GetParent() != this) { return(false); } } int oldIndex = this.IndexOfChild(child); if (oldIndex == newIndex) { return(true); } if (oldIndex > newIndex) { ++newIndex; } this.Children.RemoveAt(oldIndex); this.InsertChild(newIndex, child); return(true); }
/// <summary> /// 删除子节点。 /// </summary> /// <param name="child">被删除的子节点</param> /// <returns>如果子节点不在本对象的子节点列表中,则失败</returns> public virtual bool DeleteChild(ViNamedObject child) { if (this.Owner != null) { if (child.GetParent() != this.Owner) { return(false); } child.SetParent(null); } return(this.Children.Remove(child)); }