using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
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;
using Tango.Core;
using Tango.DragAndDrop;
using Tango.SharedUI;
namespace Tango.SharedUI.Editors
{
///
/// Represents a scrollable list of auto generated editable controls for objects which inherits from .
///
public partial class ParameterizedEditor : UserControl
{
public class GeneratingItemsEventArgs : EventArgs
{
public IEnumerable Source { get; set; }
public IEnumerable Result { get; set; }
}
public event EventHandler GeneratingItems;
///
/// Initializes a new instance of the class.
///
public ParameterizedEditor()
{
InitializeComponent();
DraggingSurface = draggingSurface;
}
///
/// Gets or sets the parameters.
///
public List Parameters
{
get { return (List)GetValue(ParametersProperty); }
set { SetValue(ParametersProperty, value); }
}
public static readonly DependencyProperty ParametersProperty =
DependencyProperty.Register("Parameters", typeof(List), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the dragging surface.
///
public DraggingSurface DraggingSurface
{
get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); }
set { SetValue(DraggingSurfaceProperty, value); }
}
public static readonly DependencyProperty DraggingSurfaceProperty =
DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the items panel.
///
public ItemsPanelTemplate ItemsPanel
{
get { return (ItemsPanelTemplate)GetValue(ItemsPanelProperty); }
set { SetValue(ItemsPanelProperty, value); }
}
public static readonly DependencyProperty ItemsPanelProperty =
DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// 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(ParameterizedEditor), new PropertyMetadata(null,(d,e) => (d as ParameterizedEditor).OnParameterizedObjectChanged()));
///
/// Gets or sets a single item padding.
///
public Thickness ItemPadding
{
get { return (Thickness)GetValue(ItemPaddingProperty); }
set { SetValue(ItemPaddingProperty, value); }
}
public static readonly DependencyProperty ItemPaddingProperty =
DependencyProperty.Register("ItemPadding", typeof(Thickness), typeof(ParameterizedEditor), new PropertyMetadata(new Thickness()));
///
/// Gets or sets a single item margin.
///
public Thickness ItemMargin
{
get { return (Thickness)GetValue(ItemMarginProperty); }
set { SetValue(ItemMarginProperty, value); }
}
public static readonly DependencyProperty ItemMarginProperty =
DependencyProperty.Register("ItemMargin", typeof(Thickness), typeof(ParameterizedEditor), new PropertyMetadata(new Thickness()));
///
/// Gets or sets a single item minimum height.
///
public double ItemMinHeight
{
get { return (double)GetValue(ItemMinHeightProperty); }
set { SetValue(ItemMinHeightProperty, value); }
}
public static readonly DependencyProperty ItemMinHeightProperty =
DependencyProperty.Register("ItemMinHeight", typeof(double), typeof(ParameterizedEditor), new PropertyMetadata(0.0));
///
/// Gets or sets a single item label margin.
///
public Thickness ItemLabelMargin
{
get { return (Thickness)GetValue(ItemLabelMarginProperty); }
set { SetValue(ItemLabelMarginProperty, value); }
}
public static readonly DependencyProperty ItemLabelMarginProperty =
DependencyProperty.Register("ItemLabelMargin", typeof(Thickness), typeof(ParameterizedEditor), new PropertyMetadata(new Thickness()));
#region Templates
///
/// Gets or sets the double template.
///
public DataTemplate DoubleTemplate
{
get { return (DataTemplate)GetValue(DoubleTemplateProperty); }
set { SetValue(DoubleTemplateProperty, value); }
}
public static readonly DependencyProperty DoubleTemplateProperty =
DependencyProperty.Register("DoubleTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the int32 template.
///
public DataTemplate Int32Template
{
get { return (DataTemplate)GetValue(Int32TemplateProperty); }
set { SetValue(Int32TemplateProperty, value); }
}
public static readonly DependencyProperty Int32TemplateProperty =
DependencyProperty.Register("Int32Template", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the single template.
///
public DataTemplate SingleTemplate
{
get { return (DataTemplate)GetValue(SingleTemplateProperty); }
set { SetValue(SingleTemplateProperty, value); }
}
public static readonly DependencyProperty SingleTemplateProperty =
DependencyProperty.Register("SingleTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the double up down template.
///
public DataTemplate DoubleUpDownTemplate
{
get { return (DataTemplate)GetValue(DoubleUpDownTemplateProperty); }
set { SetValue(DoubleUpDownTemplateProperty, value); }
}
public static readonly DependencyProperty DoubleUpDownTemplateProperty =
DependencyProperty.Register("DoubleUpDownTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the boolean template.
///
public DataTemplate BooleanTemplate
{
get { return (DataTemplate)GetValue(BooleanTemplateProperty); }
set { SetValue(BooleanTemplateProperty, value); }
}
public static readonly DependencyProperty BooleanTemplateProperty =
DependencyProperty.Register("BooleanTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the enum template.
///
public DataTemplate EnumTemplate
{
get { return (DataTemplate)GetValue(EnumTemplateProperty); }
set { SetValue(EnumTemplateProperty, value); }
}
public static readonly DependencyProperty EnumTemplateProperty =
DependencyProperty.Register("EnumTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the color template.
///
public DataTemplate ColorTemplate
{
get { return (DataTemplate)GetValue(ColorTemplateProperty); }
set { SetValue(ColorTemplateProperty, value); }
}
public static readonly DependencyProperty ColorTemplateProperty =
DependencyProperty.Register("ColorTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the brush template.
///
public DataTemplate BrushTemplate
{
get { return (DataTemplate)GetValue(BrushTemplateProperty); }
set { SetValue(BrushTemplateProperty, value); }
}
public static readonly DependencyProperty BrushTemplateProperty =
DependencyProperty.Register("BrushTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
///
/// Gets or sets the string template.
///
public DataTemplate StringTemplate
{
get { return (DataTemplate)GetValue(StringTemplateProperty); }
set { SetValue(StringTemplateProperty, value); }
}
public static readonly DependencyProperty StringTemplateProperty =
DependencyProperty.Register("StringTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));
#endregion
private void OnParameterizedObjectChanged()
{
if (ParameterizedObject != null)
{
GeneratingItemsEventArgs e = new GeneratingItemsEventArgs();
e.Source = ParameterizedObject.Parameters;
e.Result = ParameterizedObject.Parameters;
GeneratingItems?.Invoke(this, e);
Parameters = e.Result.ToList();
}
else
{
Parameters = null;
}
}
}
}