From 6cc65250c62e89ff706c42d90edd0de6f5a11aca Mon Sep 17 00:00:00 2001 From: Roman Agafonov Date: Sun, 17 Nov 2024 02:29:16 +0300 Subject: [PATCH] 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);