// -----------------------------------------------------------------------
//
// Copyright 2015 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using Perspex.Controls.Primitives;
using Perspex.Controls.Templates;
using System;
///
/// A control used to indicate the progress of an operation.
///
public class ProgressBar : RangeBase
{
static ProgressBar()
{
ValueProperty.Changed.AddClassHandler(x => x.ValueChanged);
}
private Border indicator;
///
///
protected override void OnTemplateApplied()
{
this.indicator = this.GetTemplateChild("PART_Indicator");
}
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;
}
}
}
}