CommandHelper.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using System.Collections.Generic;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Data;
  5. namespace Aitex.Sorter.UI.Controls.Common
  6. {
  7. public class CommandHelper
  8. {
  9. public const string TransferCommandName = "WaferTransfer";
  10. public static object GetParameter1(DependencyObject obj)
  11. {
  12. return (object)obj.GetValue(Parameter1Property);
  13. }
  14. public static void SetParameter1(DependencyObject obj, object value)
  15. {
  16. obj.SetValue(Parameter1Property, value);
  17. }
  18. // Using a DependencyProperty as the backing store for Parameter1. This enables animation, styling, binding, etc...
  19. public static readonly DependencyProperty Parameter1Property =
  20. DependencyProperty.RegisterAttached("Parameter1", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  21. public static object GetParameter2(DependencyObject obj)
  22. {
  23. return (object)obj.GetValue(Parameter2Property);
  24. }
  25. public static void SetParameter2(DependencyObject obj, object value)
  26. {
  27. obj.SetValue(Parameter2Property, value);
  28. }
  29. // Using a DependencyProperty as the backing store for Parameter2. This enables animation, styling, binding, etc...
  30. public static readonly DependencyProperty Parameter2Property =
  31. DependencyProperty.RegisterAttached("Parameter2", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  32. public static object GetParameter3(DependencyObject obj)
  33. {
  34. return (object)obj.GetValue(Parameter3Property);
  35. }
  36. public static void SetParameter3(DependencyObject obj, object value)
  37. {
  38. obj.SetValue(Parameter3Property, value);
  39. }
  40. // Using a DependencyProperty as the backing store for Parameter3. This enables animation, styling, binding, etc...
  41. public static readonly DependencyProperty Parameter3Property =
  42. DependencyProperty.RegisterAttached("Parameter3", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  43. public static string GetCommandName(DependencyObject obj)
  44. {
  45. return (string)obj.GetValue(CommandNameProperty);
  46. }
  47. public static void SetCommandName(DependencyObject obj, string value)
  48. {
  49. obj.SetValue(CommandNameProperty, value);
  50. }
  51. // Using a DependencyProperty as the backing store for CommandCode. This enables animation, styling, binding, etc...
  52. public static readonly DependencyProperty CommandNameProperty =
  53. DependencyProperty.RegisterAttached("CommandName", typeof(string), typeof(CommandHelper), new PropertyMetadata(null, CommandNameChanged));
  54. public static object GetTarget(DependencyObject obj)
  55. {
  56. return (object)obj.GetValue(TargetProperty);
  57. }
  58. public static void SetTarget(DependencyObject obj, string value)
  59. {
  60. obj.SetValue(TargetProperty, value);
  61. }
  62. // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
  63. public static readonly DependencyProperty TargetProperty =
  64. DependencyProperty.RegisterAttached("Target", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  65. static void CommandNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  66. {
  67. BindingOperations.SetBinding(d, Button.CommandParameterProperty, new Binding() { Source = d });
  68. }
  69. public static object GetParameter4(DependencyObject obj)
  70. {
  71. return (object)obj.GetValue(Parameter4Property);
  72. }
  73. public static void SetParameter4(DependencyObject obj, object value)
  74. {
  75. obj.SetValue(Parameter4Property, value);
  76. }
  77. // Using a DependencyProperty as the backing store for Parameter4. This enables animation, styling, binding, etc...
  78. public static readonly DependencyProperty Parameter4Property =
  79. DependencyProperty.RegisterAttached("Parameter4", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  80. public static object GetParameter5(DependencyObject obj)
  81. {
  82. return (object)obj.GetValue(Parameter5Property);
  83. }
  84. public static void SetParameter5(DependencyObject obj, object value)
  85. {
  86. obj.SetValue(Parameter5Property, value);
  87. }
  88. // Using a DependencyProperty as the backing store for Parameter5. This enables animation, styling, binding, etc...
  89. public static readonly DependencyProperty Parameter5Property =
  90. DependencyProperty.RegisterAttached("Parameter5", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  91. public static object GetParameter6(DependencyObject obj)
  92. {
  93. return (object)obj.GetValue(Parameter6Property);
  94. }
  95. public static void SetParameter6(DependencyObject obj, object value)
  96. {
  97. obj.SetValue(Parameter6Property, value);
  98. }
  99. // Using a DependencyProperty as the backing store for Parameter6. This enables animation, styling, binding, etc...
  100. public static readonly DependencyProperty Parameter6Property =
  101. DependencyProperty.RegisterAttached("Parameter6", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  102. public static object GetParameter7(DependencyObject obj)
  103. {
  104. return (object)obj.GetValue(Parameter7Property);
  105. }
  106. public static void SetParameter7(DependencyObject obj, object value)
  107. {
  108. obj.SetValue(Parameter7Property, value);
  109. }
  110. // Using a DependencyProperty as the backing store for Parameter7. This enables animation, styling, binding, etc...
  111. public static readonly DependencyProperty Parameter7Property =
  112. DependencyProperty.RegisterAttached("Parameter7", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  113. public static object GetParameter8(DependencyObject obj)
  114. {
  115. return (object)obj.GetValue(Parameter8Property);
  116. }
  117. public static void SetParameter8(DependencyObject obj, object value)
  118. {
  119. obj.SetValue(Parameter8Property, value);
  120. }
  121. // Using a DependencyProperty as the backing store for Parameter8. This enables animation, styling, binding, etc...
  122. public static readonly DependencyProperty Parameter8Property =
  123. DependencyProperty.RegisterAttached("Parameter8", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  124. public static object GetParameter9(DependencyObject obj)
  125. {
  126. return (object)obj.GetValue(Parameter9Property);
  127. }
  128. public static void SetParameter9(DependencyObject obj, object value)
  129. {
  130. obj.SetValue(Parameter9Property, value);
  131. }
  132. // Using a DependencyProperty as the backing store for Parameter9. This enables animation, styling, binding, etc...
  133. public static readonly DependencyProperty Parameter9Property =
  134. DependencyProperty.RegisterAttached("Parameter9", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  135. public static object GetParameter10(DependencyObject obj)
  136. {
  137. return (object)obj.GetValue(Parameter10Property);
  138. }
  139. public static void SetParameter10(DependencyObject obj, object value)
  140. {
  141. obj.SetValue(Parameter10Property, value);
  142. }
  143. // Using a DependencyProperty as the backing store for Parameter10. This enables animation, styling, binding, etc...
  144. public static readonly DependencyProperty Parameter10Property =
  145. DependencyProperty.RegisterAttached("Parameter10", typeof(object), typeof(CommandHelper), new PropertyMetadata(null));
  146. public static CommandItem GetCommandItem(DependencyObject sender)
  147. {
  148. var target = GetTarget(sender);
  149. var name = GetCommandName(sender);
  150. var paras = new List<object>();
  151. var p1 = GetParameter1(sender);
  152. if (p1 != null)
  153. {
  154. paras.Add(p1);
  155. var p2 = GetParameter2(sender);
  156. if (p2 != null)
  157. {
  158. paras.Add(p2);
  159. var p3 = GetParameter3(sender);
  160. if (p3 != null)
  161. {
  162. paras.Add(p3);
  163. var p4 = GetParameter4(sender);
  164. if (p4 != null)
  165. {
  166. paras.Add(p4);
  167. var p5 = GetParameter5(sender);
  168. if (p5 != null)
  169. {
  170. paras.Add(p5);
  171. var p6= GetParameter6(sender);
  172. if (p6 != null)
  173. {
  174. paras.Add(p6);
  175. var p7 = GetParameter7(sender);
  176. if (p7 != null)
  177. {
  178. paras.Add(p7);
  179. var p8 = GetParameter8(sender);
  180. if (p8 != null)
  181. {
  182. paras.Add(p8);
  183. var p9 = GetParameter9(sender);
  184. if (p9 != null)
  185. {
  186. paras.Add(p9);
  187. var p10 = GetParameter10(sender);
  188. if (p10 != null)
  189. {
  190. paras.Add(p10);
  191. }
  192. }
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. return new CommandItem { Target = target, CommandName = name, Parameters = paras.ToArray() };
  202. }
  203. }
  204. public class CommandItem
  205. {
  206. public object Target { get; set; }
  207. public string CommandName { get; set; }
  208. public object[] Parameters { get; set; }
  209. }
  210. }