7 changed files with 143 additions and 28 deletions
@ -0,0 +1,37 @@ |
|||
namespace Perspex.Controls.Primitives |
|||
{ |
|||
using System; |
|||
using System.Reactive; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Controls.Templates; |
|||
|
|||
public abstract class RangeBase : TemplatedControl |
|||
{ |
|||
public static readonly PerspexProperty<double> MinimumProperty = |
|||
PerspexProperty.Register<RangeBase, double>("Minimum"); |
|||
|
|||
public static readonly PerspexProperty<double> MaximumProperty = |
|||
PerspexProperty.Register<RangeBase, double>("Maximum", defaultValue: 100.0); |
|||
|
|||
public static readonly PerspexProperty<double> ValueProperty = |
|||
PerspexProperty.Register<RangeBase, double>("Value"); |
|||
|
|||
public double Minimum |
|||
{ |
|||
get { return this.GetValue(MinimumProperty); } |
|||
set { this.SetValue(MinimumProperty, value); } |
|||
} |
|||
|
|||
public double Maximum |
|||
{ |
|||
get { return this.GetValue(MaximumProperty); } |
|||
set { this.SetValue(MaximumProperty, value); } |
|||
} |
|||
|
|||
public double Value |
|||
{ |
|||
get { return this.GetValue(ValueProperty); } |
|||
set { this.SetValue(ValueProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
namespace Perspex.Controls |
|||
{ |
|||
using System; |
|||
using System.Reactive; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Controls.Templates; |
|||
using Perspex.Controls.Primitives; |
|||
|
|||
public class ProgressBar : RangeBase |
|||
{ |
|||
public static readonly PerspexProperty<bool> IsIndeterminateProperty = |
|||
PerspexProperty.Register<ProgressBar, bool>("IsIndeterminate", defaultValue: false); |
|||
|
|||
public static readonly PerspexProperty<Orientation> OrientationProperty = |
|||
PerspexProperty.Register<ProgressBar, Orientation>("Orientation", defaultValue: Orientation.Horizontal); |
|||
|
|||
protected override Size ArrangeOverride(Size finalSize) |
|||
{ |
|||
var size = base.ArrangeOverride(finalSize); |
|||
var b = this.Bounds; |
|||
|
|||
var indicator = this.GetTemplateChild<Border>("PART_Indicator"); |
|||
indicator.Width = finalSize.Width * (this.Value / 100); |
|||
|
|||
return size; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
namespace Perspex.Themes.Default |
|||
{ |
|||
using System.Linq; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Presenters; |
|||
using Perspex.Controls.Primitives; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Layout; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
|
|||
public class ProgressBarStyle : Styles |
|||
{ |
|||
public ProgressBarStyle() |
|||
{ |
|||
this.AddRange(new[] |
|||
{ |
|||
new Style(x => x.OfType<ProgressBar>()) |
|||
{ |
|||
Setters = new[] |
|||
{ |
|||
new Setter(ProgressBar.TemplateProperty, ControlTemplate.Create<ProgressBar>(this.Template)), |
|||
new Setter(ProgressBar.BackgroundProperty, new SolidColorBrush(0xffdddddd)), |
|||
new Setter(ProgressBar.ForegroundProperty, new SolidColorBrush(0xffbee6fd)), |
|||
}, |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private Control Template(ProgressBar control) |
|||
{ |
|||
Border container = new Border |
|||
{ |
|||
[~Border.BackgroundProperty] = control[~ProgressBar.BackgroundProperty], |
|||
[~Border.BorderBrushProperty] = control[~ProgressBar.BorderBrushProperty], |
|||
[~Border.BorderThicknessProperty] = control[~ProgressBar.BorderThicknessProperty], |
|||
|
|||
Content = new Grid |
|||
{ |
|||
MinHeight = 14, |
|||
MinWidth = 200, |
|||
|
|||
Children = new Controls |
|||
{ |
|||
new Border |
|||
{ |
|||
Name = "PART_Track", |
|||
BorderThickness = 1, |
|||
[~Border.BorderBrushProperty] = control[~ProgressBar.BackgroundProperty], |
|||
}, |
|||
|
|||
new Border |
|||
{ |
|||
Name = "PART_Indicator", |
|||
BorderThickness = 1, |
|||
HorizontalAlignment = HorizontalAlignment.Left, |
|||
[~Border.BackgroundProperty] = control[~ProgressBar.ForegroundProperty], |
|||
|
|||
Content = new Grid |
|||
{ |
|||
Name = "Animation", |
|||
ClipToBounds = true, |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
|
|||
return container; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue