using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace Tango.FSE.Statistics.Controls { public class RangeProgressBar : Control { private Border _innerBorder; private Border _outerBorder; static RangeProgressBar() { DefaultStyleKeyProperty.OverrideMetadata(typeof(RangeProgressBar), new FrameworkPropertyMetadata(typeof(RangeProgressBar))); } public Brush FillBrush { get { return (Brush)GetValue(FillBrushProperty); } set { SetValue(FillBrushProperty, value); } } public static readonly DependencyProperty FillBrushProperty = DependencyProperty.Register("FillBrush", typeof(Brush), typeof(RangeProgressBar), new PropertyMetadata(Brushes.Red)); public double Maximum { get { return (double)GetValue(MaximumProperty); } set { SetValue(MaximumProperty, value); } } public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(RangeProgressBar), new PropertyMetadata(100.0)); public double LowerValue { get { return (double)GetValue(LowerValueProperty); } set { SetValue(LowerValueProperty, value); } } public static readonly DependencyProperty LowerValueProperty = DependencyProperty.Register("LowerValue", typeof(double), typeof(RangeProgressBar), new PropertyMetadata(20.0)); public double UpperValue { get { return (double)GetValue(UpperValueProperty); } set { SetValue(UpperValueProperty, value); } } public static readonly DependencyProperty UpperValueProperty = DependencyProperty.Register("UpperValue", typeof(double), typeof(RangeProgressBar), new PropertyMetadata(80.0)); public override void OnApplyTemplate() { base.OnApplyTemplate(); _innerBorder = GetTemplateChild("PART_InnerBorder") as Border; _outerBorder = GetTemplateChild("PART_OuterBorder") as Border; PlaceInnerBorder(); SizeChanged -= RangeProgressBar_SizeChanged; SizeChanged += RangeProgressBar_SizeChanged; } private void RangeProgressBar_SizeChanged(object sender, SizeChangedEventArgs e) { PlaceInnerBorder(); } private void PlaceInnerBorder() { double leftMargin = LowerValue / Maximum * _outerBorder.ActualWidth; double rightMargin = _outerBorder.ActualWidth - (UpperValue / Maximum * _outerBorder.ActualWidth); leftMargin = Double.IsNaN(leftMargin) ? 0 : leftMargin; rightMargin = Double.IsNaN(rightMargin) ? 0 : rightMargin; _innerBorder.Margin = new Thickness(leftMargin, 0, rightMargin, 0); } } }