From e8d5dae0b39223f1656e08de31a8f3f15fea75ad Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sat, 25 Jul 2015 15:52:29 -0400 Subject: [PATCH 1/2] Fixed a bug in ProgressBar --- Perspex.Controls/ProgressBar.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Perspex.Controls/ProgressBar.cs b/Perspex.Controls/ProgressBar.cs index 232039b802..2afbd3bc87 100644 --- a/Perspex.Controls/ProgressBar.cs +++ b/Perspex.Controls/ProgressBar.cs @@ -8,6 +8,7 @@ namespace Perspex.Controls { using Perspex.Controls.Primitives; using Perspex.Controls.Templates; + using System; /// /// A control used to indicate the progress of an operation. @@ -21,7 +22,7 @@ namespace Perspex.Controls var b = this.Bounds; var indicator = this.GetTemplateChild("PART_Indicator"); - indicator.Width = finalSize.Width * (this.Value / 100); + indicator.Width = Math.Max(this.Minimum, finalSize.Width * (this.Value / this.Maximum)); return size; } From 08ca269a093e4aff3cb37195c0d998bdb8ed8901 Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sat, 25 Jul 2015 16:40:35 -0400 Subject: [PATCH 2/2] Correctly subtracted the minimum from the value and the divisor. --- Perspex.Controls/ProgressBar.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Perspex.Controls/ProgressBar.cs b/Perspex.Controls/ProgressBar.cs index 2afbd3bc87..f14751a0e7 100644 --- a/Perspex.Controls/ProgressBar.cs +++ b/Perspex.Controls/ProgressBar.cs @@ -16,13 +16,15 @@ namespace Perspex.Controls public class ProgressBar : RangeBase { /// + /// + private Border indicator; protected override Size ArrangeOverride(Size finalSize) { var size = base.ArrangeOverride(finalSize); - var b = this.Bounds; - - var indicator = this.GetTemplateChild("PART_Indicator"); - indicator.Width = Math.Max(this.Minimum, finalSize.Width * (this.Value / this.Maximum)); + this.indicator = this.indicator ?? this.GetTemplateChild("PART_Indicator"); + + double percent = this.Maximum == this.Minimum ? 1.0 : (this.Value - this.Minimum) / (this.Maximum - this.Minimum); + indicator.Width = finalSize.Width * percent; return size; }