public EventTypesViewModel() { var events = DeserializeEvents(); EventTypesUI = new EventItems { EventTypes = new ObservableCollection <EventTypes>() }; RefreshEventTypeTree(events); }
private void RefreshEventTypeTree(EventItems events) { foreach (var item in events.EventTypes.ToList()) { if (item.ParentId == -1) { item.Children = new ObservableCollection <EventTypes>(); var eventsChilds = events.EventTypes.Where(child => child.ParentId == item.EventTypeId).ToList(); foreach (var child in eventsChilds) { item.Children.Add(child); } EventTypesUI.EventTypes.Add(item); } } }