From 22def65643e6cc0a643f540192c06be9649c5664 Mon Sep 17 00:00:00 2001 From: Roman Agafonov Date: Sun, 17 Nov 2024 02:29:16 +0300 Subject: [PATCH 1/2] Fix DataTable crash on resize when columns don't fit. --- components/DataTable/src/DataTable/DataTable.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/DataTable/src/DataTable/DataTable.cs b/components/DataTable/src/DataTable/DataTable.cs index 65a3c1b81..039e0e8bf 100644 --- a/components/DataTable/src/DataTable/DataTable.cs +++ b/components/DataTable/src/DataTable/DataTable.cs @@ -93,7 +93,12 @@ protected override Size MeasureOverride(Size availableSize) // then invalidate the child arranges [don't re-measure and cause loop]...) // For now, we'll just use the header content as a guideline to see if things work. - column.Measure(new Size(availableSize.Width - fixedWidth - autoSized, availableSize.Height)); + + // Avoid negative values when columns don't fit `availableSize`. Otherwise the `Size` constructor will throw. + double width = availableSize.Width - fixedWidth - autoSized; + if (width < 0) + width = 0; + column.Measure(new Size(width, availableSize.Height)); // Keep track of already 'allotted' space, use either the maximum child size (if we know it) or the header content autoSized += Math.Max(column.DesiredSize.Width, column.MaxChildDesiredWidth); From e375d9a1d27c94b718253939db81626f0c34ffe5 Mon Sep 17 00:00:00 2001 From: Roman Agafonov Date: Wed, 11 Dec 2024 02:00:37 +0300 Subject: [PATCH 2/2] Use Max() instead of conditional statement Suggested in code review, see !599 Co-authored-by: Andrii Chebukin --- components/DataTable/src/DataTable/DataTable.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/DataTable/src/DataTable/DataTable.cs b/components/DataTable/src/DataTable/DataTable.cs index 039e0e8bf..f42df3e50 100644 --- a/components/DataTable/src/DataTable/DataTable.cs +++ b/components/DataTable/src/DataTable/DataTable.cs @@ -96,8 +96,7 @@ protected override Size MeasureOverride(Size availableSize) // Avoid negative values when columns don't fit `availableSize`. Otherwise the `Size` constructor will throw. double width = availableSize.Width - fixedWidth - autoSized; - if (width < 0) - width = 0; + width = Math.Max(width, 0); column.Measure(new Size(width, availableSize.Height)); // Keep track of already 'allotted' space, use either the maximum child size (if we know it) or the header content