diff --git a/Perspex.Controls/ProgressBar.cs b/Perspex.Controls/ProgressBar.cs index f14751a0e7..bcc97a4404 100644 --- a/Perspex.Controls/ProgressBar.cs +++ b/Perspex.Controls/ProgressBar.cs @@ -15,18 +15,27 @@ namespace Perspex.Controls /// public class ProgressBar : RangeBase { + static ProgressBar() + { + ValueProperty.Changed.AddClassHandler(x => x.ValueChanged); + } + + private Border indicator; + /// /// - private Border indicator; - protected override Size ArrangeOverride(Size finalSize) + protected override void OnTemplateApplied() { - var size = base.ArrangeOverride(finalSize); - 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; + this.indicator = this.GetTemplateChild("PART_Indicator"); + } - return size; + private void ValueChanged(PerspexPropertyChangedEventArgs e) + { + if (this.indicator != null) + { + double percent = this.Maximum == this.Minimum ? 1.0 : ((double)e.NewValue - this.Minimum) / (this.Maximum - this.Minimum); + this.indicator.Width = this.Bounds.Width * percent; + } } } }