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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Tango.Core
{
/// <summary>
/// Represents a component parameter name and value which can be bound to UI elements.
/// </summary>
/// <seealso cref="System.Windows.DependencyObject" />
public class ParameterItem : DependencyObject
{
/// <summary>
/// Occurs when the parameter value has changed.
/// </summary>
public event EventHandler<ParameterItem> ParameterValueChanged;
/// <summary>
/// Gets or sets the parameterized object.
/// </summary>
public IParameterized ParameterizedObject
{
get { return (IParameterized)GetValue(ParameterizedObjectProperty); }
set { SetValue(ParameterizedObjectProperty, value); }
}
public static readonly DependencyProperty ParameterizedObjectProperty =
DependencyProperty.Register("ParameterizedObject", typeof(IParameterized), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the parameter index.
/// </summary>
public int Index
{
get { return (int)GetValue(IndexProperty); }
set { SetValue(IndexProperty, value); }
}
public static readonly DependencyProperty IndexProperty =
DependencyProperty.Register("Index", typeof(int), typeof(ParameterItem), new PropertyMetadata(0));
/// <summary>
/// Gets or sets the parameter value type.
/// </summary>
public Type Type
{
get { return (Type)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}
public static readonly DependencyProperty TypeProperty =
DependencyProperty.Register("Type", typeof(Type), typeof(ParameterItem), new PropertyMetadata(typeof(double)));
/// <summary>
/// Gets or sets the parameter name.
/// </summary>
public String Name
{
get { return (String)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(String), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the current parameter value.
/// </summary>
public object Value
{
get { return (object)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(object), typeof(ParameterItem), new PropertyMetadata(null, new PropertyChangedCallback(OnValueChanged)));
/// <summary>
/// Gets or sets the minimum parameter value.
/// </summary>
public object Minimum
{
get { return (object)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(object), typeof(ParameterItem), new PropertyMetadata(0.0d));
/// <summary>
/// Gets or sets the maximum parameter value.
/// </summary>
public object Maximum
{
get { return (object)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(object), typeof(ParameterItem), new PropertyMetadata(1.0d));
/// <summary>
/// Gets or sets an optional extra object.
/// </summary>
public object ExtraObject
{
get { return (object)GetValue(ExtraObjectProperty); }
set { SetValue(ExtraObjectProperty, value); }
}
public static readonly DependencyProperty ExtraObjectProperty =
DependencyProperty.Register("ExtraObject", typeof(object), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets an optional custom editor.
/// </summary>
public String CustomEditorTypeName
{
get { return (String)GetValue(CustomEditorTypeNameProperty); }
set { SetValue(CustomEditorTypeNameProperty, value); }
}
public static readonly DependencyProperty CustomEditorTypeNameProperty =
DependencyProperty.Register("CustomEditorType", typeof(String), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the parameter description.
/// </summary>
public String Description
{
get { return (String)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(String), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the parameter string format.
/// </summary>
public String StringFormat
{
get { return (String)GetValue(StringFormatProperty); }
set { SetValue(StringFormatProperty, value); }
}
public static readonly DependencyProperty StringFormatProperty =
DependencyProperty.Register("StringFormat", typeof(String), typeof(ParameterItem), new PropertyMetadata("0.0"));
/// <summary>
/// Gets a value indicating whether this instance requires custom editor.
/// </summary>
public bool HasCustomEditor
{
get { return false; }
}
/// <summary>
/// Called when value has changed.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as ParameterItem).OnParameterChanged();
}
/// <summary>
/// Called when the parameter value has changed.
/// </summary>
protected virtual void OnParameterChanged()
{
if (ParameterValueChanged != null) ParameterValueChanged(this, this);
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
return Name;
}
}
}
|