Browse Source

Merge pull request #65 from ncarrillo/fix-progress-bar

Fix progress bar
pull/66/head
Steven Kirk 11 years ago
parent
commit
f1deacdc74
  1. 25
      Perspex.Controls/ProgressBar.cs

25
Perspex.Controls/ProgressBar.cs

@ -15,18 +15,27 @@ namespace Perspex.Controls
/// </summary>
public class ProgressBar : RangeBase
{
static ProgressBar()
{
ValueProperty.Changed.AddClassHandler<ProgressBar>(x => x.ValueChanged);
}
private Border indicator;
/// <inheritdoc/>
///
private Border indicator;
protected override Size ArrangeOverride(Size finalSize)
protected override void OnTemplateApplied()
{
var size = base.ArrangeOverride(finalSize);
this.indicator = this.indicator ?? this.GetTemplateChild<Border>("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<Border>("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;
}
}
}
}

Loading…
Cancel
Save