From d7c83c9cc0551bf727ce8cc7bb03b861a2f784c4 Mon Sep 17 00:00:00 2001 From: k-hara Date: Wed, 18 Feb 2026 00:06:26 +0900 Subject: [PATCH] DataRow lay out children like a horizontal StackPanel if DataTable is not present This added behavior just covers a corner case. If a user fails to place corresponding DataTable at correct position, displaying somethings is better than nothing. Each rows layout their columns independent, because there's no main controller to remember the column widths, and then it looks like a horizontal StackPanel. --- components/DataTable/src/DataTable/DataRow.cs | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) 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) {