RecipeLoadControl.xaml.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using MECF.Framework.Common.RecipeCenter;
  2. using PunkHPX8_Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace PunkHPX8_Themes.UserControls
  21. {
  22. /// <summary>
  23. /// RecipeLoad.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class RecipeLoadControl : UserControl
  26. {
  27. public RecipeLoadControl()
  28. {
  29. InitializeComponent();
  30. }
  31. public static readonly DependencyProperty SelectedRecipeNodeProperty = DependencyProperty.Register( "SelectedRecipeNode", typeof(RecipeNode), typeof(RecipeLoadControl),
  32. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  33. /// <summary>
  34. /// 当前选中recipe节点
  35. /// </summary>
  36. public RecipeNode SelectedRecipeNode
  37. {
  38. get
  39. {
  40. return (RecipeNode)this.GetValue(SelectedRecipeNodeProperty);
  41. }
  42. set
  43. {
  44. this.SetValue(SelectedRecipeNodeProperty, value);
  45. }
  46. }
  47. public static readonly DependencyProperty RecipeTypeProperty = DependencyProperty.Register(
  48. "RecipeType", typeof(string), typeof(RecipeLoadControl),new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  49. /// <summary>
  50. /// recipe类型
  51. /// </summary>
  52. public string RecipeType
  53. {
  54. get
  55. {
  56. return (string)this.GetValue(RecipeTypeProperty);
  57. }
  58. set
  59. {
  60. this.SetValue(RecipeTypeProperty, value);
  61. }
  62. }
  63. public static readonly DependencyProperty RecipeNodesProperty = DependencyProperty.
  64. Register("RecipeNodes", typeof(ObservableCollection<RecipeNode>), typeof(RecipeLoadControl));
  65. public ObservableCollection<RecipeNode> RecipeNodes
  66. {
  67. get { return (ObservableCollection<RecipeNode>)this.GetValue(RecipeNodesProperty); }
  68. set { this.SetValue(RecipeNodesProperty, value); }
  69. }
  70. public static readonly DependencyProperty IsDummyLoadSelectedProperty = DependencyProperty.Register(
  71. "IsDummyLoadSelected", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnItemsSourceChanged)));
  72. /// <summary>
  73. /// IsDummyLoadSelected
  74. /// </summary>
  75. public bool IsDummyLoadSelected
  76. {
  77. get
  78. {
  79. return (bool)this.GetValue(IsDummyLoadSelectedProperty);
  80. }
  81. set
  82. {
  83. this.SetValue(IsDummyLoadSelectedProperty, value);
  84. }
  85. }
  86. private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  87. {
  88. // 将 DependencyObject 转换为当前控件实例
  89. if (d is RecipeLoadControl control)
  90. {
  91. control.UpdateRecipeNodes(); // 调用共用逻辑
  92. }
  93. }
  94. private void Self_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  95. {
  96. if (e.NewValue != null)
  97. {
  98. bool result = (bool)e.NewValue;
  99. if (result)
  100. {
  101. UpdateRecipeNodes();
  102. }
  103. }
  104. }
  105. public static readonly DependencyProperty IsEngineeringModeProperty = DependencyProperty.Register(
  106. "IsEngineeringMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  107. /// <summary>
  108. /// IsEngineeringMode
  109. /// </summary>
  110. public bool IsEngineeringMode
  111. {
  112. get
  113. {
  114. return (bool)this.GetValue(IsEngineeringModeProperty);
  115. }
  116. set
  117. {
  118. this.SetValue(IsEngineeringModeProperty, value);
  119. }
  120. }
  121. public static readonly DependencyProperty IsProductionModeProperty = DependencyProperty.Register(
  122. "IsProductionMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  123. /// <summary>
  124. /// IsProductionMode
  125. /// </summary>
  126. public bool IsProductionMode
  127. {
  128. get
  129. {
  130. return (bool)this.GetValue(IsProductionModeProperty);
  131. }
  132. set
  133. {
  134. this.SetValue(IsProductionModeProperty, value);
  135. }
  136. }
  137. private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  138. {
  139. RecipeNode recipeNode = (RecipeNode)e.NewValue;
  140. if (recipeNode != null)
  141. {
  142. if(recipeNode.NodeType== RecipeNodeType.File)
  143. {
  144. SelectedRecipeNode = recipeNode;
  145. }
  146. else
  147. {
  148. SelectedRecipeNode = null;
  149. }
  150. }
  151. else
  152. {
  153. SelectedRecipeNode = null;
  154. }
  155. }
  156. private void UpdateRecipeNodes()
  157. {
  158. if (!string.IsNullOrEmpty(RecipeType))
  159. {
  160. if ("dep".Equals(RecipeType) && IsDummyLoadSelected)
  161. {
  162. RecipeNodes = RecipeClient.Instance.Service.GetRecipesByType("dqdr");
  163. }
  164. else
  165. {
  166. RecipeNodes = RecipeClient.Instance.Service.GetRecipesByType(RecipeType);
  167. }
  168. }
  169. }
  170. }
  171. }