From fab1ce30d28f444ece4702276613fe411e897528 Mon Sep 17 00:00:00 2001 From: cricketthomas Date: Thu, 21 May 2026 20:04:05 -0400 Subject: [PATCH 1/3] add column width measurements and support for horizontal scrolling --- .../DataTableVirtualizationSample.xaml | 9 +++++++-- components/DataTable/src/DataTable/DataRow.cs | 5 +++-- .../DataTable/src/DataTable/DataTable.cs | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/components/DataTable/samples/DataTableVirtualizationSample.xaml b/components/DataTable/samples/DataTableVirtualizationSample.xaml index 6b3204cd7..75211ef98 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..4009df412 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 + 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..46033b468 100644 --- a/components/DataTable/src/DataTable/DataTable.cs +++ b/components/DataTable/src/DataTable/DataTable.cs @@ -18,12 +18,31 @@ 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) + { + if (column.CurrentWidth.IsAbsolute) + totalWidth += column.CurrentWidth.Value; + else + totalWidth += Math.Max(column.DesiredSize.Width, column.MaxChildDesiredWidth); + } + + _ = elements.TryGetNonEnumeratedCount(out int count); + totalWidth += Math.Max(0, count - 1) * ColumnSpacing; + return totalWidth; + } + internal void ColumnResized() { InvalidateArrange(); foreach (var row in Rows) { + row.InvalidateMeasure(); row.InvalidateArrange(); } } From 0ad5e4b3123e9328a145bbfb21948fa73b466d8b Mon Sep 17 00:00:00 2001 From: cricketthomas Date: Thu, 21 May 2026 20:30:35 -0400 Subject: [PATCH 2/3] use count function --- .../DataTable/samples/DataTableVirtualizationSample.xaml | 2 +- components/DataTable/src/DataTable/DataTable.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/DataTable/samples/DataTableVirtualizationSample.xaml b/components/DataTable/samples/DataTableVirtualizationSample.xaml index 75211ef98..62f70b156 100644 --- a/components/DataTable/samples/DataTableVirtualizationSample.xaml +++ b/components/DataTable/samples/DataTableVirtualizationSample.xaml @@ -34,7 +34,7 @@ - + diff --git a/components/DataTable/src/DataTable/DataTable.cs b/components/DataTable/src/DataTable/DataTable.cs index 46033b468..4160e71b1 100644 --- a/components/DataTable/src/DataTable/DataTable.cs +++ b/components/DataTable/src/DataTable/DataTable.cs @@ -31,8 +31,7 @@ internal double CalculateDesiredWidth() totalWidth += Math.Max(column.DesiredSize.Width, column.MaxChildDesiredWidth); } - _ = elements.TryGetNonEnumeratedCount(out int count); - totalWidth += Math.Max(0, count - 1) * ColumnSpacing; + totalWidth += Math.Max(0, elements.Count() - 1) * ColumnSpacing; return totalWidth; } From da77c010d86ac94bf36abe9568a23656128cfe99 Mon Sep 17 00:00:00 2001 From: cricketthomas Date: Thu, 21 May 2026 20:37:44 -0400 Subject: [PATCH 3/3] fix: VS warnings --- components/DataTable/src/DataTable/DataRow.cs | 2 +- components/DataTable/src/DataTable/DataTable.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/DataTable/src/DataTable/DataRow.cs b/components/DataTable/src/DataTable/DataRow.cs index 4009df412..40be99b37 100644 --- a/components/DataTable/src/DataTable/DataRow.cs +++ b/components/DataTable/src/DataTable/DataRow.cs @@ -171,7 +171,7 @@ protected override Size MeasureOverride(Size availableSize) // TODO: What do we want to do if there's unequal children in the DataTable vs. DataRow? } - // Use the calculated desired width from the parent table if available + // 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 4160e71b1..5fb1ee905 100644 --- a/components/DataTable/src/DataTable/DataTable.cs +++ b/components/DataTable/src/DataTable/DataTable.cs @@ -23,12 +23,16 @@ internal double CalculateDesiredWidth() double totalWidth = 0; var elements = Children.Where(static e => e.Visibility == Visibility.Visible && e is DataColumn); - foreach (DataColumn column in elements) + 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;