From f08871fe7d148d667f2f11f80f64de71a0d9504c Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 15 六月 2026 18:19:37 +0800
Subject: [PATCH] 优化标准老化界面

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

diff --git a/HMI.UI/DpUtil/DataGridHelper.cs b/HMI.UI/DpUtil/DataGridHelper.cs
index b9fce70..bf113c1 100644
--- a/HMI.UI/DpUtil/DataGridHelper.cs
+++ b/HMI.UI/DpUtil/DataGridHelper.cs
@@ -16,5 +16,41 @@
         public static readonly DependencyProperty SelectedColumnProperty =
             DependencyProperty.RegisterAttached("SelectedColumn", typeof(DataGridColumn), typeof(Grid),
                 new PropertyMetadata(null));
+
+        public static bool GetShowRowNumber(DependencyObject obj)
+        {
+            return (bool)obj.GetValue(ShowRowNumberProperty);
+        }
+        public static void SetShowRowNumber(DependencyObject obj, bool value)
+        {
+            obj.SetValue(ShowRowNumberProperty, value);
+        }
+
+        public static readonly DependencyProperty ShowRowNumberProperty =
+            DependencyProperty.RegisterAttached("ShowRowNumber", typeof(bool), typeof(DataGrid),
+                new PropertyMetadata(false, OnShowRowNumberChanged));
+
+        private static void OnShowRowNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            if (d is DataGrid grid)
+            {
+                if (e.Property == ShowRowNumberProperty)
+                {
+                    if (((bool)e.NewValue))
+                    {
+                        grid.LoadingRow += Grid_LoadingRow;
+                    }
+                    else
+                    {
+                        grid.LoadingRow -= Grid_LoadingRow;
+                    }
+                }
+            }
+        }
+
+        private static void Grid_LoadingRow(object sender, DataGridRowEventArgs e)
+        {
+            e.Row.Header = e.Row.GetIndex() + 1;
+        }
     }
 }

--
Gitblit v1.9.1