From 633c479175795aebdbd573931ec0a021ca2b9d00 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 12 Jul 2022 09:21:38 +0200 Subject: [PATCH] Use indicators parent if available to determine the space We used controls bounds before, which may lead to wrong indicator size if a border is set or the template has elements next to the indicator. --- src/Avalonia.Controls/ProgressBar.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Controls/ProgressBar.cs b/src/Avalonia.Controls/ProgressBar.cs index 70edeadfd9..d0e8e8f1a0 100644 --- a/src/Avalonia.Controls/ProgressBar.cs +++ b/src/Avalonia.Controls/ProgressBar.cs @@ -195,7 +195,7 @@ namespace Avalonia.Controls /// protected override Size ArrangeOverride(Size finalSize) { - UpdateIndicator(finalSize); + UpdateIndicator(); return base.ArrangeOverride(finalSize); } @@ -218,18 +218,21 @@ namespace Avalonia.Controls { _indicator = e.NameScope.Get("PART_Indicator"); - UpdateIndicator(Bounds.Size); + UpdateIndicator(); } - private void UpdateIndicator(Size bounds) + private void UpdateIndicator() { + // Gets the size of the parent indicator container + var barSize = _indicator?.Parent?.Bounds.Size ?? Bounds.Size; + if (_indicator != null) { if (IsIndeterminate) { // Pulled from ModernWPF. - var dim = Orientation == Orientation.Horizontal ? bounds.Width : bounds.Height; + var dim = Orientation == Orientation.Horizontal ? barSize.Width : barSize.Height; var barIndicatorWidth = dim * 0.4; // Indicator width at 40% of ProgressBar var barIndicatorWidth2 = dim * 0.6; // Indicator width at 60% of ProgressBar @@ -254,8 +257,8 @@ namespace Avalonia.Controls new Rect( padding.Left, padding.Top, - bounds.Width - (padding.Right + padding.Left), - bounds.Height - (padding.Bottom + padding.Top) + barSize.Width - (padding.Right + padding.Left), + barSize.Height - (padding.Bottom + padding.Top) )); } else @@ -263,9 +266,9 @@ namespace Avalonia.Controls double percent = Maximum == Minimum ? 1.0 : (Value - Minimum) / (Maximum - Minimum); if (Orientation == Orientation.Horizontal) - _indicator.Width = bounds.Width * percent; + _indicator.Width = barSize.Width * percent; else - _indicator.Height = bounds.Height * percent; + _indicator.Height = barSize.Height * percent; Percentage = percent * 100; } @@ -274,7 +277,7 @@ namespace Avalonia.Controls private void UpdateIndicatorWhenPropChanged(AvaloniaPropertyChangedEventArgs e) { - UpdateIndicator(Bounds.Size); + UpdateIndicator(); } private void UpdatePseudoClasses(