From d1b72117058f1131046b6aa3add8e3ccfae033d8 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 10:36:07 +0800
Subject: [PATCH] docs: CAN 模拟器独立 TCP 服务进程设计规格(统一 CanDeviceDriver + 双工推送协议)

---
 HMI.UI/DpUtil/FormGroupHelper.cs |   45 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/HMI.UI/DpUtil/FormGroupHelper.cs b/HMI.UI/DpUtil/FormGroupHelper.cs
index feda1f9..bc45159 100644
--- a/HMI.UI/DpUtil/FormGroupHelper.cs
+++ b/HMI.UI/DpUtil/FormGroupHelper.cs
@@ -1,5 +1,6 @@
 锘縰sing HMI.Core.Util;
 using Panuon.WPF.UI;
+using System.Collections.Generic;
 using System.Windows;
 using System.Windows.Controls;
 
@@ -49,7 +50,7 @@
             DependencyProperty.RegisterAttached("ValidateMethod", typeof(ValidateMethodDelegate), typeof(FormGroupHelper),
             new PropertyMetadata(null));
 
-        public static bool ValidateForm(StackPanel fgPanel)
+        public static bool ValidateForm(StackPanel fgPanel, Dictionary<string, object> values = null)
         {
             if (fgPanel.Children == null) return true;
             bool res = true;
@@ -57,10 +58,25 @@
             {
                 if (child is FormGroup fg)
                 {
+                    string fgName = fg.Name;
+                    if (fg.Visibility != Visibility.Visible)
+                    {
+                        ClearValue(fg);
+                        continue;
+                    }
                     fg.ValidateResult = ValidateResult.None;
                     fg.Message = null;
-                    object content = fg.Content;
-                    object value = GetValidateValue(content);
+                    object value;
+                    if (values != null && values.ContainsKey(fgName))
+                    {
+                        value = values[fgName];
+                    }
+                    else
+                    {
+                        object content = fg.Content;
+                        value = GetValidateValue(content);
+                    }
+
                     if (GetIsRequired(fg) && (value == null || string.IsNullOrEmpty(value.ToString())))
                     {
                         fg.ValidateResult = ValidateResult.Error;
@@ -89,12 +105,31 @@
                 return elementCollection.Count > 0 ? GetValidateValue(elementCollection[0]) : null;
             if (content is TextBox tb) return tb.Text;
             if (content is CheckBox cb) return cb.IsChecked;
-            if (content is ComboBox cBox) return cBox.SelectedValue;
+            if (content is ComboBox cBox) return cBox.SelectedItem ?? cBox.SelectedValue ?? cBox.Text;
 
             if (content is Panel panel) return GetValidateValue(panel.Children);
-            if (content is NumberInput numberInput) return numberInput.Value;
+            if (content is Panuon.WPF.UI.NumberInput numberInput) return numberInput.Value;
             if (content is PasswordBox passwordInput) return passwordInput.Password;
             return null;
         }
+
+        private static void ClearValue(object content)
+        {
+            if (content == null) return;
+            if (content is UIElementCollection elementCollection && elementCollection.Count > 0)
+                ClearValue(elementCollection[0]);
+            if (content is TextBox tb) tb.Text = null;
+            if (content is CheckBox cb) cb.IsChecked = null;
+            if (content is ComboBox cBox)
+            {
+                cBox.SelectedItem = null;
+                cBox.SelectedValue = null;
+                cBox.Text = null;
+            }
+
+            if (content is Panel panel) ClearValue(panel.Children);
+            if (content is Panuon.WPF.UI.NumberInput numberInput) numberInput.Value = null;
+            if (content is PasswordBox passwordInput) passwordInput.Password = null;
+        }
     }
 }

--
Gitblit v1.9.1