From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 HMI.UI/DpUtil/StackPanelHelper.cs |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/HMI.UI/DpUtil/StackPanelHelper.cs b/HMI.UI/DpUtil/StackPanelHelper.cs
new file mode 100644
index 0000000..ffe05eb
--- /dev/null
+++ b/HMI.UI/DpUtil/StackPanelHelper.cs
@@ -0,0 +1,54 @@
+锘縰sing System.Windows;
+using System.Windows.Controls;
+
+namespace HMI.UI.DpUtil
+{
+    public class StackPanelHelper
+    {
+        public static double GetChildSpace(StackPanel sp)
+        {
+            return (double)sp.GetValue(ChildSpaceProperty);
+        }
+
+        public static void SetChildSpace(StackPanel sp, double value)
+        {
+            sp.SetValue(ChildSpaceProperty, value);
+        }
+
+        public static readonly DependencyProperty ChildSpaceProperty =
+            DependencyProperty.RegisterAttached("ChildSpace", typeof(double), typeof(StackPanelHelper),
+            new PropertyMetadata(0d, (d, e) =>
+            {
+                if (!(d is StackPanel sp)) return;
+                sp.Loaded += Sp_Loaded;
+            }));
+
+        private static void Sp_Loaded(object sender, RoutedEventArgs e)
+        {
+            var sp = sender as StackPanel;
+            var children = sp.Children;
+            if (sp.Children == null) return;
+            double space = GetChildSpace(sp);
+            if (sp.Orientation == Orientation.Horizontal)
+            {
+                for (int i = 0; i < children.Count; i++)
+                {
+                    if (children[i] is FrameworkElement ui)
+                    {
+                        ui.Margin = new Thickness(0, 0, (i == children.Count - 1) ? 0 : space, 0);
+                    }
+                }
+            }
+            else
+            {
+                for (int i = 0; i < children.Count; i++)
+                {
+                    if (children[i] is FrameworkElement ui)
+                    {
+                        ui.Margin = new Thickness(0, 0, 0, (i == children.Count - 1) ? 0 : space);
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1