private void SetList(List <DTObject> items) { Items = DTOPool.CreateObjectList(this, this.IsPinned); if (items.Count == 0) { this.ItemTemplate = this.IsPinned ? DTObject.Create() : DTObject.CreateReusable(); } else { if (items.Count == 1) { DTObject item = items[0]; if (item.ContainsData()) { Items.Add(item); } this.ItemTemplate = item.Clone(); } else { foreach (var item in items) { Items.Add(item); } this.ItemTemplate = Items[0].Clone(); } this.ItemTemplate.ForceClearData(); } }
/// <summary> /// 新建一个子项,并将新建的子项加入集合中 /// </summary> /// <returns></returns> public void CreateAndPush(Action <DTObject> fill) { DTObject obj = this.ItemTemplate.Clone(); Items.Add(obj); if (fill != null) { fill(obj); } this.Changed(); }