RecipeLoadControl.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using MECF.Framework.Common.RecipeCenter;
  2. using CyberX8_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.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace CyberX8_Themes.UserControls
  20. {
  21. /// <summary>
  22. /// RecipeLoad.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class RecipeLoadControl : UserControl
  25. {
  26. public RecipeLoadControl()
  27. {
  28. InitializeComponent();
  29. }
  30. public static readonly DependencyProperty SelectedRecipeNodeProperty = DependencyProperty.Register( "SelectedRecipeNode", typeof(RecipeNode), typeof(RecipeLoadControl),
  31. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  32. /// <summary>
  33. /// 当前选中recipe节点
  34. /// </summary>
  35. public RecipeNode SelectedRecipeNode
  36. {
  37. get
  38. {
  39. return (RecipeNode)this.GetValue(SelectedRecipeNodeProperty);
  40. }
  41. set
  42. {
  43. this.SetValue(SelectedRecipeNodeProperty, value);
  44. }
  45. }
  46. public static readonly DependencyProperty RecipeTypeProperty = DependencyProperty.Register(
  47. "RecipeType", typeof(string), typeof(RecipeLoadControl),new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  48. /// <summary>
  49. /// recipe类型
  50. /// </summary>
  51. public string RecipeType
  52. {
  53. get
  54. {
  55. return (string)this.GetValue(RecipeTypeProperty);
  56. }
  57. set
  58. {
  59. this.SetValue(RecipeTypeProperty, value);
  60. }
  61. }
  62. public static readonly DependencyProperty RecipeNodesProperty = DependencyProperty.
  63. Register("RecipeNodes", typeof(ObservableCollection<RecipeNode>), typeof(RecipeLoadControl));
  64. public ObservableCollection<RecipeNode> RecipeNodes
  65. {
  66. get { return (ObservableCollection<RecipeNode>)this.GetValue(RecipeNodesProperty); }
  67. set { this.SetValue(RecipeNodesProperty, value); }
  68. }
  69. private void Self_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  70. {
  71. if (e.NewValue != null)
  72. {
  73. bool result = (bool)e.NewValue;
  74. if (result)
  75. {
  76. if (!string.IsNullOrEmpty(RecipeType))
  77. {
  78. RecipeNodes = RecipeClient.Instance.Service.GetRecipesByType(RecipeType);
  79. }
  80. }
  81. }
  82. }
  83. public static readonly DependencyProperty IsEngineeringModeProperty = DependencyProperty.Register(
  84. "IsEngineeringMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  85. /// <summary>
  86. /// IsEngineeringMode
  87. /// </summary>
  88. public bool IsEngineeringMode
  89. {
  90. get
  91. {
  92. return (bool)this.GetValue(IsEngineeringModeProperty);
  93. }
  94. set
  95. {
  96. this.SetValue(IsEngineeringModeProperty, value);
  97. }
  98. }
  99. public static readonly DependencyProperty IsProductionModeProperty = DependencyProperty.Register(
  100. "IsProductionMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  101. /// <summary>
  102. /// IsProductionMode
  103. /// </summary>
  104. public bool IsProductionMode
  105. {
  106. get
  107. {
  108. return (bool)this.GetValue(IsProductionModeProperty);
  109. }
  110. set
  111. {
  112. this.SetValue(IsProductionModeProperty, value);
  113. }
  114. }
  115. private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  116. {
  117. RecipeNode recipeNode = (RecipeNode)e.NewValue;
  118. if (recipeNode != null)
  119. {
  120. if(recipeNode.NodeType== RecipeNodeType.File)
  121. {
  122. SelectedRecipeNode = recipeNode;
  123. }
  124. else
  125. {
  126. SelectedRecipeNode = null;
  127. }
  128. }
  129. else
  130. {
  131. SelectedRecipeNode = null;
  132. }
  133. }
  134. }
  135. }