From 6bcafc823e836ecd5790f87178a906333699f868 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 10 四月 2025 10:46:47 +0800
Subject: [PATCH] 优化插件结构;

---
 WPFProject/Controls/MainTabControl.xaml.cs |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/WPFProject/Controls/MainTabControl.xaml.cs b/WPFProject/Controls/MainTabControl.xaml.cs
index 1e57271..874fe44 100644
--- a/WPFProject/Controls/MainTabControl.xaml.cs
+++ b/WPFProject/Controls/MainTabControl.xaml.cs
@@ -1,16 +1,13 @@
 锘縰sing HMI.Base;
 using HMI.Core.Api;
-using Microsoft.DwayneNeed.Interop;
 using Panuon.WPF.UI;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
-using System.Windows.Forms.Integration;
-using System.Windows.Media;
-using WPFProject.UI;
 
 namespace WPFProject.Controls
 {
@@ -41,7 +38,6 @@
         private WinFormHolder winFormHolder;
         public MainTabControl()
         {
-            IPlugin plugin = new WorkControl();
             MenuItems = new ObservableCollection<PluginInfo>(PluginLoader.GetLoader().Menus);
             SubMenuItems = MenuItems[0].Children;
             this.DataContext = this;
@@ -94,6 +90,7 @@
             }
         }
 
+        private Dictionary<PluginInfo, PluginInfo> selectedCache = new Dictionary<PluginInfo, PluginInfo>();
 
         private ObservableCollection<PluginInfo> _SubMenuItems;
 
@@ -138,20 +135,27 @@
             {
                 var data = (PluginInfo)e.AddedItems[0];
                 SubMenuItems = data?.Children;
+                if (selectedCache.ContainsKey(data))
+                {
+                    SelectedSubMenu = selectedCache[data];
+                }
+                else if (SubMenuItems.Count > 0)
+                {
+                    SelectedSubMenu = SubMenuItems[0];
+                }
             }
         }
-
-        private void SwithMenu(PluginInfo menu)
-        {
-
-        }
-
 
         private void SubMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             if (e.AddedItems?.Count > 0)
             {
                 var data = (PluginInfo)e.AddedItems[0];
+                if (SelectedMenu != null)
+                {
+                    selectedCache[SelectedMenu] = data;
+                }
+
                 var content = data.Content;
                 var last = page.Child;
                 PluginPackage.Get(last)?.DeActive();
@@ -186,6 +190,11 @@
                 UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
             };
             winFormHolder.SetBinding(WinFormHolder.MaskVisiableProperty, binding);
+            if (MenuItems != null && MenuItems.Count > 0)
+            {
+                SelectedMenu = MenuItems[0];
+            }
+            Loaded -= UserControl_Loaded;
         }
     }
 }

--
Gitblit v1.9.1