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 | 85 +++++++++++++++++++++++++++++-------------
1 files changed, 59 insertions(+), 26 deletions(-)
diff --git a/WPFProject/Controls/MainTabControl.xaml.cs b/WPFProject/Controls/MainTabControl.xaml.cs
index 874fe44..6b3fba5 100644
--- a/WPFProject/Controls/MainTabControl.xaml.cs
+++ b/WPFProject/Controls/MainTabControl.xaml.cs
@@ -1,6 +1,7 @@
锘縰sing HMI.Base;
using HMI.Core.Api;
using Panuon.WPF.UI;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -11,6 +12,12 @@
namespace WPFProject.Controls
{
+ public class TabChangedEventArg
+ {
+ public IPlugin oldValue { get; set; }
+ public IPlugin newValue { get; set; }
+ }
+
/// <summary>
/// MainTabControl.xaml 鐨勪氦浜掗�昏緫
/// </summary>
@@ -46,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;
@@ -157,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)
@@ -175,26 +186,48 @@
{
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];
}
Loaded -= UserControl_Loaded;
}
+
+ private string alarmInfo;
+ public string AlarmInfo
+ {
+ get => alarmInfo;
+ set
+ {
+ RaiseAndSetIfChanged(ref alarmInfo, value);
+ }
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ alarmBorder.Visibility = Visibility.Collapsed;
+ AlarmInfo = string.Empty;
+ }
+
+ public void ShowAlarm(string message)
+ {
+ AlarmInfo = message;
+ alarmBorder.Visibility = Visibility.Visible;
+ }
}
}
--
Gitblit v1.9.1