From 07f3ad23e49da9ced46b7a68392e78a150622c35 Mon Sep 17 00:00:00 2001 From: Kieran Devlin Date: Mon, 23 Dec 2024 09:43:22 +0000 Subject: [PATCH] Clamp progressbar indicator width and height to never drop below zero when calculating size. (#17816) Fixes #17393 --- src/Avalonia.Controls/ProgressBar.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/ProgressBar.cs b/src/Avalonia.Controls/ProgressBar.cs index 220931b4f4..89ca28f5cc 100644 --- a/src/Avalonia.Controls/ProgressBar.cs +++ b/src/Avalonia.Controls/ProgressBar.cs @@ -378,17 +378,17 @@ namespace Avalonia.Controls // Indicator size calculation should consider the ProgressBar's Padding property setting if (Orientation == Orientation.Horizontal) { - _indicator.Width = (barSize.Width - _indicator.Margin.Left - _indicator.Margin.Right) * percent; + var width = (barSize.Width - _indicator.Margin.Left - _indicator.Margin.Right) * percent; + _indicator.Width = width > 0 ? width : 0; _indicator.Height = double.NaN; } else { _indicator.Width = double.NaN; - _indicator.Height = (barSize.Height - _indicator.Margin.Top - _indicator.Margin.Bottom) * - percent; + var height = (barSize.Height - _indicator.Margin.Top - _indicator.Margin.Bottom) * percent; + _indicator.Height = height > 0 ? height : 0; } - Percentage = percent * 100; } }