1: /// <summary>
2: /// aktiviert das automatische snappen an Tciks im Ziffernblatt
3: /// </summary>
4: public bool IsSnapToTickEnabled
5: {
6: get { return (bool)GetValue(IsSnapToTickEnabledProperty); }
7: set { SetValue(IsSnapToTickEnabledProperty, value); }
8: }
9:
10: // Using a DependencyProperty as the backing store for IsSnapToTickEnabled. This enables animation, styling, binding, etc...
11: public static readonly DependencyProperty IsSnapToTickEnabledProperty =
12: DependencyProperty.Register("IsSnapToTickEnabled", typeof(bool), typeof(GaugeControl), new PropertyMetadata(false));
13:
14:
15: /// <summary>
16: /// Frequenz für Skala des Messgerätes
17: /// </summary>
18: public int TickFrequency
19: {
20: get
21: {
22: return (int)GetValue(TickFrequencyProperty);
23: }
24: set
25: {
26: SetValue(TickFrequencyProperty, value);
27: }
28: }
29:
30: /// <summary>
31: /// Dependency Property für TickFrequency
32: /// </summary>
33: public static readonly DependencyProperty TickFrequencyProperty =
34: DependencyProperty.Register("TickFrequency", typeof(int), typeof(GaugeControl), new PropertyMetadata(12, OnTickFrequencyChanged));
35:
36: /// <summary>
37: /// Callback für Änderung der Tickfrequenz
38: /// berechnet neue Tickfrequenz abhängig vom Minimum und Maximum
39: /// </summary>
40: /// <param name="d">Modifizierte DependencyObject</param>
41: /// <param name="e">Infos über geänderte Attribute</param>
42: private static void OnTickFrequencyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
43: {
44: var t = d as GaugeControl;
45:
46: if (t != null)
47: {
48: double newTicks = ((t.Maximum - t.Minimum) / (int)e.NewValue);
49: t.TickCount = Convert.ToInt32(newTicks);
50: }
51: }
52:
53: /// <summary>
54: /// Enthält die berechnete Anzahl der anzuzeigenden Ticks aus Tickfrequency, Minimum und Maximum
55: /// </summary>
56: private int TickCount
57: {
58: get { return (int)GetValue(TickCountProperty); }
59: set { SetValue(TickCountProperty, value); }
60: }
61:
62: // Using a DependencyProperty as the backing store for TickCount. This enables animation, styling, binding, etc...
63: public static readonly DependencyProperty TickCountProperty =
64: DependencyProperty.Register("TickCount", typeof(int), typeof(GaugeControl), new PropertyMetadata(null));
65:
66:
67:
68: /// <summary>
69: /// Aktueller Anzeigewert des Messgerätes
70: /// </summary>
71: public double Value
72: {
73: get { return (double)GetValue(ValueProperty); }
74: set { SetValue(ValueProperty, value); }
75: }
76:
77: /// <summary>
78: /// Dependency Property für Aktuellen Anzeigewert
79: /// </summary>
80: public static readonly DependencyProperty ValueProperty =
81: DependencyProperty.Register("Value", typeof(double), typeof(GaugeControl), new PropertyMetadata(0.0, OnValueChanged));
82:
83: /// <summary>
84: /// Anpassung der Rotation des Zeigers unter Einbezug des Minimum und Maximum falls eine Wertänderung vorliegt
85: /// </summary>
86: /// <param name="d"></param>
87: /// <param name="e"></param>
88: private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
89: {
90: var t = d as GaugeControl;
91:
92: if (t != null)
93: {
94: double newValue = (double)e.NewValue;
95: double newAngle = MathExtensions.RemapValue(newValue, t.Minimum, t.Maximum, 0, 360);
96: t.Needle.RenderTransform = new RotateTransform(newAngle);
97: }
98: }
99:
100: /// <summary>
101: /// Untere Grenze des Wertebereichs für das Messgerät
102: /// </summary>
103: public double Minimum
104: {
105: get { return (double)GetValue(MinimumProperty); }
106: set { SetValue(MinimumProperty, value); }
107: }
108:
109: /// <summary>
110: /// Dependency Property für Minimum
111: /// </summary>
112: public static readonly DependencyProperty MinimumProperty =
113: DependencyProperty.Register("Minimum", typeof(double), typeof(GaugeControl), new PropertyMetadata(0.0));
114:
115: /// <summary>
116: /// Obere Grenze des Wertebereichs für das Messgerät
117: /// </summary>
118: public double Maximum
119: {
120: get { return (double)GetValue(MaximumProperty); }
121: set { SetValue(MaximumProperty, value); }
122: }
123:
124: /// <summary>
125: /// Dependency Property für Maximum
126: /// </summary>
127: public static readonly DependencyProperty MaximumProperty =
128: DependencyProperty.Register("Maximum", typeof(double), typeof(GaugeControl), new PropertyMetadata(360.0));