diff --git a/components/DataTable/src/DataTable/DataRow.cs b/components/DataTable/src/DataTable/DataRow.cs index 6546150ae..1fba7295f 100644 --- a/components/DataTable/src/DataTable/DataRow.cs +++ b/components/DataTable/src/DataTable/DataRow.cs @@ -77,17 +77,31 @@ protected override Size MeasureOverride(Size availableSize) double maxHeight = 0; - if (Children.Count > 0) + // If we don't have a grid, just layout children like a horizontal StackPanel. + if (_parentPanel is null) { - // If we don't have a grid, just measure first child to get row height and take available space - if (_parentPanel is null) + double totalWidth = 0; + + for (int i = 0; i < Children.Count; i++) { - Children[0].Measure(availableSize); - return new Size(availableSize.Width, Children[0].DesiredSize.Height); + var child = Children[i]; + if (child?.Visibility != Visibility.Visible) + continue; + + child.Measure(availableSize); + + totalWidth += child.DesiredSize.Width; + maxHeight = Math.Max(maxHeight, child.DesiredSize.Height); } + + return new Size(totalWidth, maxHeight); + } + + if (Children.Count > 0) + { // Handle DataTable Parent - else if (_parentTable != null - && _parentTable.Children.Count == Children.Count) + if (_parentTable != null && + _parentTable.Children.Count == Children.Count) { // TODO: Need to check visibility // Measure all children since we need to determine the row's height at minimum @@ -170,19 +184,41 @@ protected override Size MeasureOverride(Size availableSize) protected override Size ArrangeOverride(Size finalSize) { + // If we don't have a grid, just layout children like a horizontal StackPanel. + if (_parentPanel is null) + { + double x = 0; + + for (int i = 0; i < Children.Count; i++) + { + var child = Children[i]; + if (child?.Visibility != Visibility.Visible) + continue; + + double width = child.DesiredSize.Width; + + child.Arrange(new Rect(x, 0, width, finalSize.Height)); + + x += width; + } + + return new Size(x, finalSize.Height); + } + int column = 0; - double x = 0; // Try and grab Column Spacing from DataTable, if not a parent Grid, if not 0. double spacing = _parentTable?.ColumnSpacing ?? (_parentPanel as Grid)?.ColumnSpacing ?? 0; - double width = 0; - if (_parentPanel != null) { + double x = 0; + int i = 0; foreach (UIElement child in Children.Where(static e => e.Visibility == Visibility.Visible)) { + double width; + if (_parentPanel is Grid grid && column < grid.ColumnDefinitions.Count) {