public static Grid CreateEntityGrid(BcsEntityNode entity) { var grid = new Grid { Background = Brushes.GreenYellow, Margin = new Thickness(10, 10, 10, 10) }; if (entity is BcsLocationNode) { var location = entity as BcsLocationNode; AddRowControlToGrid(grid, new Label { Content = $"Location: {location.Name}" }); AddRowControlToGrid(grid, CreateEntityGrid(location.Resident)); } else if (entity is BcsComponentNode) { int componentRowIndex = 1; var component = entity as BcsComponentNode; AddRowControlToGrid(grid, new Label { Content = $"Component: {component.Name}" }); AddEmptyRow(grid); if (component.AtomicAgents.Any()) { grid.RowDefinitions.Add(new RowDefinition { Height = new System.Windows.GridLength(1, GridUnitType.Star) }); componentRowIndex++; } foreach (var agent in component.AtomicAgents) { AddColumnControlToGrid(grid, CreateAgentGrid(agent), 1); } foreach (var childComponent in component.SubComponents) { AddColumnControlToGrid(grid, CreateEntityGrid(childComponent), componentRowIndex); } } return grid; }