| | |
| | | DependencyProperty.RegisterAttached("Space", typeof(double), typeof(Grid), |
| | | new PropertyMetadata(0d, OnSpaceChanged)); |
| | | |
| | | public static string GetSpaceIgnore(DependencyObject obj) |
| | | { |
| | | return (string)obj.GetValue(SpaceIgnoreProperty); |
| | | } |
| | | public static void SetSpaceIgnore(DependencyObject obj, string value) |
| | | { |
| | | obj.SetValue(SpaceIgnoreProperty, value); |
| | | } |
| | | |
| | | public static readonly DependencyProperty SpaceIgnoreProperty = |
| | | DependencyProperty.RegisterAttached("SpaceIgnore", typeof(string), typeof(Grid), |
| | | new PropertyMetadata(null, OnSpaceChanged)); |
| | | |
| | | private static void OnSpaceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| | | { |
| | | if (d is Grid grid) |
| | |
| | | return; |
| | | } |
| | | |
| | | bool ignoreTop = false, ignoreBottom = false, ignoreLeft = false, ignoreRight = false; |
| | | string baseData = GetSpaceIgnore(grid) ?? ""; |
| | | if (baseData.Contains("ALL")) |
| | | { |
| | | ignoreTop = true; |
| | | ignoreBottom = true; |
| | | ignoreLeft = true; |
| | | ignoreRight = true; |
| | | } |
| | | |
| | | if (baseData.Contains("LEFT")) |
| | | { |
| | | ignoreLeft = true; |
| | | } |
| | | if (baseData.Contains("RIGHT")) |
| | | { |
| | | ignoreRight = true; |
| | | } |
| | | if (baseData.Contains("TOP")) |
| | | { |
| | | ignoreTop = true; |
| | | } |
| | | if (baseData.Contains("BOTTOM")) |
| | | { |
| | | ignoreBottom = true; |
| | | } |
| | | |
| | | var rowCount = grid.RowDefinitions.Count; |
| | | rowCount = rowCount <= 0 ? 1 : rowCount; |
| | | var columnCount = grid.ColumnDefinitions.Count; |
| | | columnCount = columnCount <= 0 ? 1 : columnCount; |
| | | int totalCount = rowCount * columnCount; |
| | | |
| | | if (grid.Children == null) return; |
| | |
| | | int rowSpan = Grid.GetRowSpan(cell); |
| | | int colSpan = Grid.GetColumnSpan(cell); |
| | | |
| | | cell.Margin = new Thickness(space, |
| | | space, |
| | | (col + colSpan) == columnCount ? space : 0, |
| | | (row + rowSpan) == rowCount ? space : 0); |
| | | double left = (col == 0 && ignoreLeft) ? 0 : space; |
| | | double top = (row == 0 && ignoreTop) ? 0 : space; |
| | | |
| | | double right = ignoreRight ? 0 : ((col + colSpan == columnCount) ? space : 0); |
| | | double bottom = ignoreBottom ? 0 : ((row + rowSpan == rowCount) ? space : 0); |
| | | cell.Margin = new Thickness(left, top, right, bottom); |
| | | |
| | | //cell.Margin = new Thickness(space, |
| | | // space, |
| | | // (col + colSpan) == columnCount ? space : 0, |
| | | // (row + rowSpan) == rowCount ? space : 0); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | public static Brush GetInnerBorderBrush(DependencyObject obj) |
| | | public static Brush GetInnerBorderBrush(Grid obj) |
| | | { |
| | | return (Brush)obj.GetValue(InnerBorderBrushProperty); |
| | | } |
| | | public static void SetInnerBorderBrush(DependencyObject obj, Brush value) |
| | | public static void SetInnerBorderBrush(Grid obj, Brush value) |
| | | { |
| | | obj.SetValue(InnerBorderBrushProperty, value); |
| | | } |
| | | public static readonly DependencyProperty InnerBorderBrushProperty = |
| | | DependencyProperty.RegisterAttached("InnerBorderBrush", typeof(Brush), typeof(Grid), |
| | | DependencyProperty.RegisterAttached("InnerBorderBrush", typeof(Brush), typeof(GridHelper), |
| | | new PropertyMetadata(null, OnInnerBorderChanged)); |
| | | |
| | | public static double GetInnerBorder(DependencyObject obj) |
| | | public static double GetInnerBorder(Grid obj) |
| | | { |
| | | return (double)obj.GetValue(InnerBorderProperty); |
| | | var sb = obj.GetValue(InnerBorderProperty); |
| | | return double.Parse(sb.ToString()); |
| | | } |
| | | |
| | | public static void SetInnerBorder(DependencyObject obj, object value) |
| | | public static void SetInnerBorder(Grid obj, object value) |
| | | { |
| | | double dv = double.Parse(value.ToString()); |
| | | obj.SetValue(InnerBorderProperty, dv); |
| | | } |
| | | |
| | | public static readonly DependencyProperty InnerBorderProperty = |
| | | DependencyProperty.RegisterAttached("InnerBorder", typeof(object), typeof(Grid), |
| | | DependencyProperty.RegisterAttached("InnerBorder", typeof(object), typeof(GridHelper), |
| | | new PropertyMetadata(0, OnInnerBorderChanged)); |
| | | |
| | | public static string GetInnerBorderIgnore(DependencyObject obj) |
| | | public static string GetInnerBorderIgnore(Grid obj) |
| | | { |
| | | return (string)obj.GetValue(InnerBorderIgnoreProperty); |
| | | } |
| | | public static void SetInnerBorderIgnore(DependencyObject obj, string value) |
| | | public static void SetInnerBorderIgnore(Grid obj, string value) |
| | | { |
| | | obj.SetValue(InnerBorderIgnoreProperty, value); |
| | | } |
| | | |
| | | public static readonly DependencyProperty InnerBorderIgnoreProperty = |
| | | DependencyProperty.RegisterAttached("InnerBorderIgnore", typeof(string), |
| | | typeof(Grid), new PropertyMetadata("None", OnInnerBorderChanged)); |
| | | typeof(GridHelper), new PropertyMetadata("None", OnInnerBorderChanged)); |
| | | |
| | | private static void OnInnerBorderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| | | { |