diff --git a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
index f77f2447..2335124e 100644
--- a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
+++ b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
@@ -8582,7 +8582,7 @@
-
+
diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
index 5d4de83e..ad72f48a 100644
--- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
@@ -5,7 +5,7 @@
HandyControlDemo
netcoreapp3.0;netcoreapp3.1;net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;net481;net5.0-windows;net6.0-windows;net7.0-windows
..\..\Shared\HandyControlDemo_Shared\Resources\Img\icon.ico
- 0108;MSB3026;MSB3061
+ 0108;MSB3026;MSB3061;SYSLIB0014
NETSDK1138
..\..\Shared\HandyControlDemo_Shared\app.manifest
diff --git a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
index 34dd13ab..38b2ae91 100644
--- a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
@@ -6,7 +6,7 @@
Contains some simple and commonly used WPF controls
HandyControl
snupkg
- 0067;0649;1591;MSB3061;SYSLIB0003;SYSLIB0004
+ 0067;0649;1591;MSB3061;SYSLIB0003;SYSLIB0004;SYSLIB0032
NETSDK1138
..\..\Shared\HandyControl_Shared\key.snk
true
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml
index 1ab2917f..e3d89bc0 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml
@@ -2,7 +2,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
- xmlns:extension="clr-namespace:HandyControl.Tools.Extension;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension"
Background="{DynamicResource RegionBrush}">
@@ -146,10 +145,10 @@
-
+
-
+
diff --git a/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Col.cs b/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Col.cs
index 7caa97f7..bdb1158b 100644
--- a/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Col.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Col.cs
@@ -9,7 +9,7 @@ namespace HandyControl.Controls;
public class Col : ContentControl
{
public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register(
- nameof(Layout), typeof(ColLayout), typeof(Col), new PropertyMetadata(default(ColLayout)));
+ nameof(Layout), typeof(ColLayout), typeof(Col), new FrameworkPropertyMetadata(default(ColLayout), FrameworkPropertyMetadataOptions.AffectsParentMeasure));
public ColLayout Layout
{
@@ -18,7 +18,7 @@ public class Col : ContentControl
}
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register(
- nameof(Offset), typeof(int), typeof(Col), new PropertyMetadata(ValueBoxes.Int0Box));
+ nameof(Offset), typeof(int), typeof(Col), new FrameworkPropertyMetadata(ValueBoxes.Int0Box, FrameworkPropertyMetadataOptions.AffectsParentMeasure));
public int Offset
{
@@ -27,12 +27,12 @@ public class Col : ContentControl
}
public static readonly DependencyProperty SpanProperty = DependencyProperty.Register(
- nameof(Span), typeof(int), typeof(Col), new PropertyMetadata(24), OnSpanValidate);
+ nameof(Span), typeof(int), typeof(Col), new FrameworkPropertyMetadata(ColLayout.ColMaxCellCount, FrameworkPropertyMetadataOptions.AffectsParentMeasure), OnSpanValidate);
private static bool OnSpanValidate(object value)
{
var v = (int) value;
- return v is >= 1 and <= 24;
+ return v is >= 1 and <= ColLayout.ColMaxCellCount;
}
public int Span
@@ -42,7 +42,7 @@ public class Col : ContentControl
}
public static readonly DependencyProperty IsFixedProperty = DependencyProperty.Register(
- nameof(IsFixed), typeof(bool), typeof(Col), new PropertyMetadata(ValueBoxes.FalseBox));
+ nameof(IsFixed), typeof(bool), typeof(Col), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsParentMeasure));
public bool IsFixed
{
@@ -52,44 +52,26 @@ public class Col : ContentControl
internal int GetLayoutCellCount(ColLayoutStatus status)
{
- var result = 0;
-
- if (Layout != null)
+ if (Layout is not null)
{
- if (!IsFixed)
+ return status switch
{
- switch (status)
- {
- case ColLayoutStatus.Xs:
- result = Layout.Xs;
- break;
- case ColLayoutStatus.Sm:
- result = Layout.Sm;
- break;
- case ColLayoutStatus.Md:
- result = Layout.Md;
- break;
- case ColLayoutStatus.Lg:
- result = Layout.Lg;
- break;
- case ColLayoutStatus.Xl:
- result = Layout.Xl;
- break;
- case ColLayoutStatus.Xxl:
- result = Layout.Xxl;
- break;
- case ColLayoutStatus.Auto:
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(status), status, null);
- }
- }
- }
- else
- {
- result = Span;
+ ColLayoutStatus.Xs => Layout.Xs,
+ ColLayoutStatus.Sm => Layout.Sm,
+ ColLayoutStatus.Md => Layout.Md,
+ ColLayoutStatus.Lg => Layout.Lg,
+ ColLayoutStatus.Xl => Layout.Xl,
+ ColLayoutStatus.Xxl => Layout.Xxl,
+ ColLayoutStatus.Auto => 0,
+ _ => throw new ArgumentOutOfRangeException(nameof(status), status, null),
+ };
}
- return result;
+ if (IsFixed)
+ {
+ return 0;
+ }
+
+ return Span;
}
}
diff --git a/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Row.cs b/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Row.cs
index cf7a11f7..239b95d1 100644
--- a/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Row.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Panel/Grid/Row.cs
@@ -14,12 +14,15 @@ public class Row : Panel
private double _maxChildDesiredHeight;
- private double _totalAutoWidth;
+ private double _fixedWidth;
public static readonly DependencyProperty GutterProperty = DependencyProperty.Register(
- nameof(Gutter), typeof(double), typeof(Row), new PropertyMetadata(ValueBoxes.Double0Box, null, OnGutterCoerce), ValidateHelper.IsInRangeOfPosDoubleIncludeZero);
+ nameof(Gutter), typeof(double), typeof(Row), new FrameworkPropertyMetadata(
+ ValueBoxes.Double0Box, FrameworkPropertyMetadataOptions.AffectsMeasure, null, OnGutterCoerce),
+ ValidateHelper.IsInRangeOfPosDoubleIncludeZero);
- private static object OnGutterCoerce(DependencyObject d, object basevalue) => ValidateHelper.IsInRangeOfPosDoubleIncludeZero(basevalue) ? basevalue : .0;
+ private static object OnGutterCoerce(DependencyObject d, object basevalue) =>
+ ValidateHelper.IsInRangeOfPosDoubleIncludeZero(basevalue) ? basevalue : .0;
public double Gutter
{
@@ -29,51 +32,59 @@ public class Row : Panel
protected override Size MeasureOverride(Size constraint)
{
+ var gutter = Gutter;
var totalCellCount = 0;
var totalRowCount = 1;
- var gutterHalf = Gutter / 2;
- _totalAutoWidth = 0;
+ _fixedWidth = 0;
+ _maxChildDesiredHeight = 0;
+ var cols = InternalChildren.OfType().ToList();
- foreach (var child in InternalChildren.OfType())
+ foreach (var child in cols)
{
- child.Margin = new Thickness(gutterHalf);
- child.Measure(constraint);
- var childDesiredSize = child.DesiredSize;
-
- if (_maxChildDesiredHeight < childDesiredSize.Height)
- {
- _maxChildDesiredHeight = childDesiredSize.Height;
- }
-
var cellCount = child.GetLayoutCellCount(_layoutStatus);
- totalCellCount += cellCount;
-
- if (totalCellCount > ColLayout.ColMaxCellCount)
- {
- totalCellCount = cellCount;
- totalRowCount++;
- }
-
if (cellCount == 0 || child.IsFixed)
{
- _totalAutoWidth += childDesiredSize.Width;
+ child.Measure(constraint);
+ _maxChildDesiredHeight = Math.Max(_maxChildDesiredHeight, child.DesiredSize.Height);
+ _fixedWidth += child.DesiredSize.Width + gutter;
}
}
- return new Size(0, _maxChildDesiredHeight * totalRowCount - Gutter);
+ var itemWidth = (constraint.Width - _fixedWidth + gutter) / ColLayout.ColMaxCellCount;
+ itemWidth = Math.Max(0, itemWidth);
+
+ foreach (var child in cols)
+ {
+ var cellCount = child.GetLayoutCellCount(_layoutStatus);
+ if (cellCount > 0 && !child.IsFixed)
+ {
+ totalCellCount += cellCount;
+ child.Measure(new Size(cellCount * itemWidth - gutter, constraint.Height));
+ _maxChildDesiredHeight = Math.Max(_maxChildDesiredHeight, child.DesiredSize.Height);
+
+ if (totalCellCount > ColLayout.ColMaxCellCount)
+ {
+ totalCellCount = cellCount;
+ totalRowCount++;
+ }
+ }
+ }
+
+ return new Size(0, _maxChildDesiredHeight * totalRowCount);
}
protected override Size ArrangeOverride(Size finalSize)
{
+ var gutter = Gutter;
var totalCellCount = 0;
- var gutterHalf = Gutter / 2;
- var itemWidth = (finalSize.Width - _totalAutoWidth + Gutter) / ColLayout.ColMaxCellCount;
+ var cols = InternalChildren.OfType().ToList();
+ var itemWidth = (finalSize.Width - _fixedWidth + gutter) / ColLayout.ColMaxCellCount;
itemWidth = Math.Max(0, itemWidth);
- var childBounds = new Rect(-gutterHalf, -gutterHalf, 0, _maxChildDesiredHeight);
+ var childBounds = new Rect(0, 0, 0, _maxChildDesiredHeight);
_layoutStatus = ColLayout.GetLayoutStatus(finalSize.Width);
- foreach (var child in InternalChildren.OfType())
+ foreach (var child in cols)
{
if (!child.IsVisible)
{
@@ -83,19 +94,19 @@ public class Row : Panel
var cellCount = child.GetLayoutCellCount(_layoutStatus);
totalCellCount += cellCount;
- var childWidth = cellCount > 0 ? cellCount * itemWidth : child.DesiredSize.Width;
-
+ var childWidth = (cellCount > 0 && !child.IsFixed) ? cellCount * itemWidth - gutter : child.DesiredSize.Width;
childBounds.Width = childWidth;
childBounds.X += child.Offset * itemWidth;
+
if (totalCellCount > ColLayout.ColMaxCellCount)
{
- childBounds.X = -gutterHalf;
+ childBounds.X = 0;
childBounds.Y += _maxChildDesiredHeight;
totalCellCount = cellCount;
}
child.Arrange(childBounds);
- childBounds.X += childWidth;
+ childBounds.X += childWidth + gutter;
}
return finalSize;
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/DividerBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/DividerBaseStyle.xaml
index f750a15a..f78ce718 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/DividerBaseStyle.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/DividerBaseStyle.xaml
@@ -16,7 +16,7 @@
-
+
@@ -60,4 +60,4 @@
-
\ No newline at end of file
+
diff --git a/src/Shared/HandyControl_Shared/Themes/Theme.xaml b/src/Shared/HandyControl_Shared/Themes/Theme.xaml
index de20dfbc..e96e892a 100644
--- a/src/Shared/HandyControl_Shared/Themes/Theme.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Theme.xaml
@@ -8701,7 +8701,7 @@
-
+
diff --git a/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs b/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs
index 37f67cea..00433ba5 100644
--- a/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs
@@ -11,19 +11,19 @@ namespace HandyControl.Tools.Extension;
[TypeConverter(typeof(ColLayoutConverter))]
public class ColLayout : MarkupExtension
{
- public static readonly int ColMaxCellCount = 24;
+ public const int ColMaxCellCount = 24;
- public static readonly int HalfColMaxCellCount = 12;
+ public const int HalfColMaxCellCount = 12;
- public static readonly int XsMaxWidth = 768;
+ public const int XsMaxWidth = 768;
- public static readonly int SmMaxWidth = 992;
+ public const int SmMaxWidth = 992;
- public static readonly int MdMaxWidth = 1200;
+ public const int MdMaxWidth = 1200;
- public static readonly int LgMaxWidth = 1920;
+ public const int LgMaxWidth = 1920;
- public static readonly int XlMaxWidth = 2560;
+ public const int XlMaxWidth = 2560;
public int Xs { get; set; } = 24;