public MenuItem this[int index] { get { if (ChildItems.Any()) { return(ChildItems[index]); } return(null); } }
/// <summary> /// Cuts all the single-child root, returning the first child that has more than 1 child of its own. /// If the first node has 0 childs, returns itself. /// Doesn't set the new root node parent to null. /// </summary> public ObservableCollection <ModelTreeItem> Trim() { if (this.ChildItems.Count == 1) { return(ChildItems[0].Trim()); } else if (!ChildItems.Any(ci => ci.HasData)) { return(new ObservableCollection <ModelTreeItem>(ChildItems.SelectMany(ci => ci.Trim()))); } return(new ObservableCollection <ModelTreeItem>(new ModelTreeItem[] { this })); }