diff --git a/components/DataTable/samples/DataTableVirtualizationSample.xaml b/components/DataTable/samples/DataTableVirtualizationSample.xaml index 6b3204cd7..62f70b156 100644 --- a/components/DataTable/samples/DataTableVirtualizationSample.xaml +++ b/components/DataTable/samples/DataTableVirtualizationSample.xaml @@ -13,6 +13,8 @@ - + - + - + diff --git a/components/DataTable/src/DataTable/DataRow.cs b/components/DataTable/src/DataTable/DataRow.cs index 19f34e947..40be99b37 100644 --- a/components/DataTable/src/DataTable/DataRow.cs +++ b/components/DataTable/src/DataTable/DataRow.cs @@ -171,8 +171,9 @@ protected override Size MeasureOverride(Size availableSize) // TODO: What do we want to do if there's unequal children in the DataTable vs. DataRow? } - // Otherwise, return our parent's size as the desired size. - return new(_parentPanel?.DesiredSize.Width ?? availableSize.Width, maxHeight); + // Use the calculated desired width from the parent table if available, fallback to return our parent's size as the desired size + double desiredWidth = _parentTable?.CalculateDesiredWidth() ?? _parentPanel?.DesiredSize.Width ?? availableSize.Width; + return new Size(desiredWidth, maxHeight); } /// diff --git a/components/DataTable/src/DataTable/DataTable.cs b/components/DataTable/src/DataTable/DataTable.cs index cb362c761..5fb1ee905 100644 --- a/components/DataTable/src/DataTable/DataTable.cs +++ b/components/DataTable/src/DataTable/DataTable.cs @@ -18,12 +18,34 @@ public partial class DataTable : Panel // TODO: Check with Sergio if there's a better structure here, as I don't need a Dictionary like ConditionalWeakTable internal HashSet Rows { get; private set; } = new(); + internal double CalculateDesiredWidth() + { + double totalWidth = 0; + var elements = Children.Where(static e => e.Visibility == Visibility.Visible && e is DataColumn); + + foreach (DataColumn column in elements.Cast()) + { + if (column.CurrentWidth.IsAbsolute) + { + totalWidth += column.CurrentWidth.Value; + } + else + { + totalWidth += Math.Max(column.DesiredSize.Width, column.MaxChildDesiredWidth); + } + } + + totalWidth += Math.Max(0, elements.Count() - 1) * ColumnSpacing; + return totalWidth; + } + internal void ColumnResized() { InvalidateArrange(); foreach (var row in Rows) { + row.InvalidateMeasure(); row.InvalidateArrange(); } }