| | |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | |
| | | namespace HMI.UI |
| | | namespace HMI.UI.DpUtil |
| | | { |
| | | public class StackPanelHelper |
| | | { |
| | |
| | | new PropertyMetadata(0d, (d, e) => |
| | | { |
| | | if (!(d is StackPanel sp)) return; |
| | | if (sp.Children == null) return; |
| | | var children = sp.Children; |
| | | double space = (double)e.NewValue; |
| | | if (sp.Orientation == Orientation.Horizontal) |
| | | 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++) |
| | | { |
| | | for (int i = 0; i < children.Count; i++) |
| | | if (children[i] is FrameworkElement ui) |
| | | { |
| | | if (children[i] is FrameworkElement ui) |
| | | { |
| | | ui.Margin = new Thickness(0, 0, (i == children.Count - 1) ? 0 : space, 0); |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |