1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
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);
}
}
}
|