using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Tango.Core
{
///
/// Represents a component parameter name and value which can be bound to UI elements.
///
///
public class ParameterItem : DependencyObject
{
///
/// Occurs when the parameter value has changed.
///
public event EventHandler ParameterValueChanged;
///
/// Gets or sets the parameterized object.
///
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));
///
/// Gets or sets the parameter index.
///
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));
///
/// Gets or sets the parameter value type.
///
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)));
///
/// Gets or sets the parameter name.
///
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));
///
/// Gets or sets the current parameter value.
///
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)));
///
/// Gets or sets the minimum parameter value.
///
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));
///
/// Gets or sets the maximum parameter value.
///
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));
///
/// Gets or sets an optional extra object.
///
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));
///
/// Gets or sets an optional custom editor.
///
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));
///
/// Gets or sets the parameter description.
///
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));
///
/// Gets or sets the parameter string format.
///
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"));
///
/// Gets a value indicating whether this instance requires custom editor.
///
public bool HasCustomEditor
{
get { return false; }
}
///
/// Called when value has changed.
///
/// The d.
/// The instance containing the event data.
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as ParameterItem).OnParameterChanged();
}
///
/// Called when the parameter value has changed.
///
protected virtual void OnParameterChanged()
{
if (ParameterValueChanged != null) ParameterValueChanged(this, this);
}
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return Name;
}
}
}