using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Data; namespace Aitex.Sorter.UI.Controls.Common { public class CommandHelper { public const string TransferCommandName = "WaferTransfer"; public static object GetParameter1(DependencyObject obj) { return (object)obj.GetValue(Parameter1Property); } public static void SetParameter1(DependencyObject obj, object value) { obj.SetValue(Parameter1Property, value); } // Using a DependencyProperty as the backing store for Parameter1. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter1Property = DependencyProperty.RegisterAttached("Parameter1", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter2(DependencyObject obj) { return (object)obj.GetValue(Parameter2Property); } public static void SetParameter2(DependencyObject obj, object value) { obj.SetValue(Parameter2Property, value); } // Using a DependencyProperty as the backing store for Parameter2. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter2Property = DependencyProperty.RegisterAttached("Parameter2", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter3(DependencyObject obj) { return (object)obj.GetValue(Parameter3Property); } public static void SetParameter3(DependencyObject obj, object value) { obj.SetValue(Parameter3Property, value); } // Using a DependencyProperty as the backing store for Parameter3. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter3Property = DependencyProperty.RegisterAttached("Parameter3", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static string GetCommandName(DependencyObject obj) { return (string)obj.GetValue(CommandNameProperty); } public static void SetCommandName(DependencyObject obj, string value) { obj.SetValue(CommandNameProperty, value); } // Using a DependencyProperty as the backing store for CommandCode. This enables animation, styling, binding, etc... public static readonly DependencyProperty CommandNameProperty = DependencyProperty.RegisterAttached("CommandName", typeof(string), typeof(CommandHelper), new PropertyMetadata(null, CommandNameChanged)); public static object GetTarget(DependencyObject obj) { return (object)obj.GetValue(TargetProperty); } public static void SetTarget(DependencyObject obj, string value) { obj.SetValue(TargetProperty, value); } // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc... public static readonly DependencyProperty TargetProperty = DependencyProperty.RegisterAttached("Target", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); static void CommandNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { BindingOperations.SetBinding(d, Button.CommandParameterProperty, new Binding() { Source = d }); } public static object GetParameter4(DependencyObject obj) { return (object)obj.GetValue(Parameter4Property); } public static void SetParameter4(DependencyObject obj, object value) { obj.SetValue(Parameter4Property, value); } // Using a DependencyProperty as the backing store for Parameter4. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter4Property = DependencyProperty.RegisterAttached("Parameter4", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter5(DependencyObject obj) { return (object)obj.GetValue(Parameter5Property); } public static void SetParameter5(DependencyObject obj, object value) { obj.SetValue(Parameter5Property, value); } // Using a DependencyProperty as the backing store for Parameter5. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter5Property = DependencyProperty.RegisterAttached("Parameter5", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter6(DependencyObject obj) { return (object)obj.GetValue(Parameter6Property); } public static void SetParameter6(DependencyObject obj, object value) { obj.SetValue(Parameter6Property, value); } // Using a DependencyProperty as the backing store for Parameter6. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter6Property = DependencyProperty.RegisterAttached("Parameter6", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter7(DependencyObject obj) { return (object)obj.GetValue(Parameter7Property); } public static void SetParameter7(DependencyObject obj, object value) { obj.SetValue(Parameter7Property, value); } // Using a DependencyProperty as the backing store for Parameter7. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter7Property = DependencyProperty.RegisterAttached("Parameter7", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter8(DependencyObject obj) { return (object)obj.GetValue(Parameter8Property); } public static void SetParameter8(DependencyObject obj, object value) { obj.SetValue(Parameter8Property, value); } // Using a DependencyProperty as the backing store for Parameter8. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter8Property = DependencyProperty.RegisterAttached("Parameter8", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter9(DependencyObject obj) { return (object)obj.GetValue(Parameter9Property); } public static void SetParameter9(DependencyObject obj, object value) { obj.SetValue(Parameter9Property, value); } // Using a DependencyProperty as the backing store for Parameter9. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter9Property = DependencyProperty.RegisterAttached("Parameter9", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static object GetParameter10(DependencyObject obj) { return (object)obj.GetValue(Parameter10Property); } public static void SetParameter10(DependencyObject obj, object value) { obj.SetValue(Parameter10Property, value); } // Using a DependencyProperty as the backing store for Parameter10. This enables animation, styling, binding, etc... public static readonly DependencyProperty Parameter10Property = DependencyProperty.RegisterAttached("Parameter10", typeof(object), typeof(CommandHelper), new PropertyMetadata(null)); public static CommandItem GetCommandItem(DependencyObject sender) { var target = GetTarget(sender); var name = GetCommandName(sender); var paras = new List(); var p1 = GetParameter1(sender); if (p1 != null) { paras.Add(p1); var p2 = GetParameter2(sender); if (p2 != null) { paras.Add(p2); var p3 = GetParameter3(sender); if (p3 != null) { paras.Add(p3); var p4 = GetParameter4(sender); if (p4 != null) { paras.Add(p4); var p5 = GetParameter5(sender); if (p5 != null) { paras.Add(p5); var p6= GetParameter6(sender); if (p6 != null) { paras.Add(p6); var p7 = GetParameter7(sender); if (p7 != null) { paras.Add(p7); var p8 = GetParameter8(sender); if (p8 != null) { paras.Add(p8); var p9 = GetParameter9(sender); if (p9 != null) { paras.Add(p9); var p10 = GetParameter10(sender); if (p10 != null) { paras.Add(p10); } } } } } } } } } } return new CommandItem { Target = target, CommandName = name, Parameters = paras.ToArray() }; } } public class CommandItem { public object Target { get; set; } public string CommandName { get; set; } public object[] Parameters { get; set; } } }