using MECF.Framework.Common.RecipeCenter; using PunkHPX8_Core; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; 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; namespace PunkHPX8_Themes.UserControls { /// /// RecipeLoad.xaml 的交互逻辑 /// public partial class RecipeLoadControl : UserControl { public RecipeLoadControl() { InitializeComponent(); } public static readonly DependencyProperty SelectedRecipeNodeProperty = DependencyProperty.Register( "SelectedRecipeNode", typeof(RecipeNode), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); /// /// 当前选中recipe节点 /// public RecipeNode SelectedRecipeNode { get { return (RecipeNode)this.GetValue(SelectedRecipeNodeProperty); } set { this.SetValue(SelectedRecipeNodeProperty, value); } } public static readonly DependencyProperty RecipeTypeProperty = DependencyProperty.Register( "RecipeType", typeof(string), typeof(RecipeLoadControl),new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender)); /// /// recipe类型 /// public string RecipeType { get { return (string)this.GetValue(RecipeTypeProperty); } set { this.SetValue(RecipeTypeProperty, value); } } public static readonly DependencyProperty RecipeNodesProperty = DependencyProperty. Register("RecipeNodes", typeof(ObservableCollection), typeof(RecipeLoadControl)); public ObservableCollection RecipeNodes { get { return (ObservableCollection)this.GetValue(RecipeNodesProperty); } set { this.SetValue(RecipeNodesProperty, value); } } public static readonly DependencyProperty IsDummyLoadSelectedProperty = DependencyProperty.Register( "IsDummyLoadSelected", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnItemsSourceChanged))); /// /// IsDummyLoadSelected /// public bool IsDummyLoadSelected { get { return (bool)this.GetValue(IsDummyLoadSelectedProperty); } set { this.SetValue(IsDummyLoadSelectedProperty, value); } } private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // 将 DependencyObject 转换为当前控件实例 if (d is RecipeLoadControl control) { control.UpdateRecipeNodes(); // 调用共用逻辑 } } private void Self_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null) { bool result = (bool)e.NewValue; if (result) { UpdateRecipeNodes(); } } } public static readonly DependencyProperty IsEngineeringModeProperty = DependencyProperty.Register( "IsEngineeringMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); /// /// IsEngineeringMode /// public bool IsEngineeringMode { get { return (bool)this.GetValue(IsEngineeringModeProperty); } set { this.SetValue(IsEngineeringModeProperty, value); } } public static readonly DependencyProperty IsProductionModeProperty = DependencyProperty.Register( "IsProductionMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); /// /// IsProductionMode /// public bool IsProductionMode { get { return (bool)this.GetValue(IsProductionModeProperty); } set { this.SetValue(IsProductionModeProperty, value); } } private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { RecipeNode recipeNode = (RecipeNode)e.NewValue; if (recipeNode != null) { if(recipeNode.NodeType== RecipeNodeType.File) { SelectedRecipeNode = recipeNode; } else { SelectedRecipeNode = null; } } else { SelectedRecipeNode = null; } } private void UpdateRecipeNodes() { if (!string.IsNullOrEmpty(RecipeType)) { if ("dep".Equals(RecipeType) && IsDummyLoadSelected) { RecipeNodes = RecipeClient.Instance.Service.GetRecipesByType("dqdr"); } else { RecipeNodes = RecipeClient.Instance.Service.GetRecipesByType(RecipeType); } } } } }