From 559890c482f5973f06aafdfec9550fee5ba3c7f2 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 17:02:15 +0800
Subject: [PATCH] feat: CAN 模拟器 TCP 化 + 多设备并发调试 + 后台生命周期管理

---
 WPFProject/Controls/MainTabControl.xaml.cs |   64 ++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/WPFProject/Controls/MainTabControl.xaml.cs b/WPFProject/Controls/MainTabControl.xaml.cs
index 39d6077..6b3fba5 100644
--- a/WPFProject/Controls/MainTabControl.xaml.cs
+++ b/WPFProject/Controls/MainTabControl.xaml.cs
@@ -1,7 +1,7 @@
 锘縰sing HMI.Base;
 using HMI.Core.Api;
 using Panuon.WPF.UI;
-using Plugin.TestResult_WPF.Model;
+using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
@@ -12,6 +12,12 @@
 
 namespace WPFProject.Controls
 {
+    public class TabChangedEventArg
+    {
+        public IPlugin oldValue { get; set; }
+        public IPlugin newValue { get; set; }
+    }
+
     /// <summary>
     /// MainTabControl.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
@@ -47,21 +53,7 @@
         }
 
         // Tab鍒囨崲浜嬩欢
-        public static readonly RoutedEvent OnTabChangeEvent =
-             EventManager.RegisterRoutedEvent("OnTabChange", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MenuTabControl));
-
-        public event RoutedEventHandler OnTabChange
-        {
-            add
-            {
-                AddHandler(OnTabChangeEvent, value);
-            }
-
-            remove
-            {
-                RemoveHandler(OnTabChangeEvent, value);
-            }
-        }
+        public event EventHandler<TabChangedEventArg> TabChanged;
 
         private ObservableCollection<PluginInfo> _MenuItems;
 
@@ -158,8 +150,26 @@
                 }
 
                 var content = data.Content;
-                var last = page.Child;
-                PluginPackage.Get(last)?.DeActive();
+                var newPlugin = PluginPackage.Get(content);
+                var last = PluginPackage.Get(page.Child);
+
+                if (last != null && !last.CanDeActive())
+                {
+                    SelectedSubMenu = (PluginInfo)e.RemovedItems[0];
+                    return;
+                }
+
+                if (newPlugin != null && !newPlugin.CanActive())
+                {
+                    if (e.RemovedItems.Count > 0)
+                    {
+                        SelectedSubMenu = (PluginInfo)e.RemovedItems[0];
+                    }
+                    return;
+                }
+
+                last?.DeActive();
+                newPlugin?.Active();
                 if (data.Type == "WinForm")
                 {
                     if (content is System.Windows.Forms.Form form)
@@ -176,21 +186,21 @@
                 {
                     page.Child = (UIElement)content;
                 }
-
-                PluginPackage.Get(content)?.Active();
+                TabChanged?.Invoke(this, new TabChangedEventArg { oldValue = last, newValue = newPlugin });
             }
         }
 
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             var ss = ((WindowX)Window.GetWindow(this));
-            Binding binding = new Binding("IsMaskVisible")
-            {
-                Source = ((WindowX)Window.GetWindow(this)),
-                Mode = BindingMode.TwoWay,
-                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
-            };
-            winFormHolder.SetBinding(WinFormHolder.MaskVisiableProperty, binding);
+            /// binding WinformHost 閬僵
+            //Binding binding = new Binding("IsMaskVisible")
+            //{
+            //    Source = ((WindowX)Window.GetWindow(this)),
+            //    Mode = BindingMode.TwoWay,
+            //    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
+            //};
+            //winFormHolder.SetBinding(WinFormHolder.MaskVisiableProperty, binding);
             if (MenuItems != null && MenuItems.Count > 0)
             {
                 SelectedMenu = MenuItems[0];

--
Gitblit v1.9.1