From ef52fd6fd07508883dce4eb002acda59f0169e59 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 23 四月 2026 10:19:33 +0800
Subject: [PATCH] 优化;
---
HMI.UI/DpUtil/UniformGridHelper.cs | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 107 insertions(+), 1 deletions(-)
diff --git a/HMI.UI/DpUtil/UniformGridHelper.cs b/HMI.UI/DpUtil/UniformGridHelper.cs
index bcd3ebb..6f98327 100644
--- a/HMI.UI/DpUtil/UniformGridHelper.cs
+++ b/HMI.UI/DpUtil/UniformGridHelper.cs
@@ -92,7 +92,7 @@
if (child is Control control)
{
-
+
int col = i % columnCount;
int row = i / columnCount;
@@ -110,5 +110,111 @@
}
}
+
+ public static void RefreshLineSize(UniformGrid grid)
+ {
+ Thickness parentThickness = default;
+ Brush brush = default;
+ var parent = grid.Parent;
+ if (parent is System.Windows.Controls.Control parentControl)
+ {
+ parentThickness = parentControl.BorderThickness;
+ brush = parentControl.BorderBrush;
+ }
+ else if (parent is Border border)
+ {
+ parentThickness = border.BorderThickness;
+ brush = border.BorderBrush;
+ }
+
+ //var value = GetLineSize(grid);
+ //if (value == null) return;
+ //double size = (double)value;
+
+ int totalCount = grid.Children.Count;
+ var columnCount = grid.Columns;
+ int rowCount = grid.Rows;
+
+ for (int i = 0; i < totalCount; i++)
+ {
+ int row = i / columnCount;
+ int rest = i % columnCount;
+
+
+ var cell = grid.Children[i];
+
+ var bt = new Thickness(rest == 0 ? 0 : parentThickness.Left,
+ row == 0 ? 0 : parentThickness.Top,
+ rest == columnCount - 1 ? 0 : parentThickness.Right,
+ row == rowCount - 1 ? 0 : parentThickness.Bottom);
+
+ if (cell is Control child)
+ {
+ child.BorderThickness = bt;
+ child.BorderBrush = brush;
+ }
+ }
+ }
+
+ public static void RefreshDefault(UniformGrid grid, ControlTemplate template)
+ {
+ int totalCount = grid.Columns * grid.Rows;
+
+ int rest = totalCount - grid.Children.Count;
+ if (rest <= 0) return;
+
+ for (int i = 0; i < rest; i++)
+ {
+ var control = new Control
+ {
+ Template = template
+ };
+ grid.Children.Add(control);
+ }
+ }
+
+ public static ControlTemplate GetDefaultTemplate(DependencyObject obj)
+ {
+ return (ControlTemplate)obj.GetValue(DefaultTemplateProperty);
+ }
+ public static void SetDefaultTemplate(DependencyObject obj, ControlTemplate value)
+ {
+ obj.SetValue(DefaultTemplateProperty, value);
+ }
+ public static readonly DependencyProperty DefaultTemplateProperty =
+ DependencyProperty.RegisterAttached("DefaultTemplate", typeof(ControlTemplate), typeof(UniformGrid),
+ new PropertyMetadata(null, OnDefaultTemplateChanged));
+
+ private static void OnDefaultTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is UniformGrid grid)
+ {
+ if (e.Property == DefaultTemplateProperty)
+ {
+ var tem = GetDefaultTemplate(grid);
+ if (tem == null) return;
+
+ //var rowCount = grid.Rows;
+ int columnCount = grid.Columns;
+ int totalCount = grid.Children.Count;
+ int rowCount = totalCount / columnCount;
+ int last = totalCount % columnCount;
+ if (last == 0)
+ {
+ return;
+ }
+ int addCount = columnCount - last;
+
+ for (int i = 0; i < addCount; i++)
+ {
+ Button u = new Button
+ {
+ Template = tem
+ };
+ grid.Children.Add(u);
+ }
+ }
+ }
+ }
}
}
--
Gitblit v1.9.1