This commit is contained in:
NaBian committed 2023-06-07 22:48:50 +08:00
1 parent 4206bfd61c
commit 81ddae5f58
9 files changed
+81 -89

No files matched your search

@@ -8582,7 +8582,7 @@
<hc:Col Layout="12" x:Name="ColStart"> <hc:Col Layout="12" x:Name="ColStart">
<Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square" /> <Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square" />
</hc:Col> </hc:Col>
<hc:Col Layout="0"> <hc:Col IsFixed="True">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" /> <ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" />
</hc:Col> </hc:Col>
<hc:Col Layout="12" x:Name="ColEnd"> <hc:Col Layout="12" x:Name="ColEnd">
@@ -5,7 +5,7 @@
<RootNamespace>HandyControlDemo</RootNamespace> <RootNamespace>HandyControlDemo</RootNamespace>
<TargetFrameworks>netcoreapp3.0;netcoreapp3.1;net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;net481;net5.0-windows;net6.0-windows;net7.0-windows</TargetFrameworks> <TargetFrameworks>netcoreapp3.0;netcoreapp3.1;net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;net481;net5.0-windows;net6.0-windows;net7.0-windows</TargetFrameworks>
<ApplicationIcon>..\..\Shared\HandyControlDemo_Shared\Resources\Img\icon.ico</ApplicationIcon> <ApplicationIcon>..\..\Shared\HandyControlDemo_Shared\Resources\Img\icon.ico</ApplicationIcon>
<NoWarn>0108;MSB3026;MSB3061</NoWarn> <NoWarn>0108;MSB3026;MSB3061;SYSLIB0014</NoWarn>
<MSBuildWarningsAsMessages>NETSDK1138</MSBuildWarningsAsMessages> <MSBuildWarningsAsMessages>NETSDK1138</MSBuildWarningsAsMessages>
<ApplicationManifest>..\..\Shared\HandyControlDemo_Shared\app.manifest</ApplicationManifest> <ApplicationManifest>..\..\Shared\HandyControlDemo_Shared\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
@@ -6,7 +6,7 @@
<Description>Contains some simple and commonly used WPF controls</Description> <Description>Contains some simple and commonly used WPF controls</Description>
<PackageId>HandyControl</PackageId> <PackageId>HandyControl</PackageId>
<SymbolPackageFormat>snupkg</SymbolPackageFormat> <SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>0067;0649;1591;MSB3061;SYSLIB0003;SYSLIB0004</NoWarn> <NoWarn>0067;0649;1591;MSB3061;SYSLIB0003;SYSLIB0004;SYSLIB0032</NoWarn>
<MSBuildWarningsAsMessages>NETSDK1138</MSBuildWarningsAsMessages> <MSBuildWarningsAsMessages>NETSDK1138</MSBuildWarningsAsMessages>
<AssemblyOriginatorKeyFile>..\..\Shared\HandyControl_Shared\key.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\..\Shared\HandyControl_Shared\key.snk</AssemblyOriginatorKeyFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
@@ -2,7 +2,6 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:extension="clr-namespace:HandyControl.Tools.Extension;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs" xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension" xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension"
Background="{DynamicResource RegionBrush}"> Background="{DynamicResource RegionBrush}">
@@ -146,10 +145,10 @@
<hc:Col Layout="4 6 8 9 11"> <hc:Col Layout="4 6 8 9 11">
<Border Background="{DynamicResource SecondaryBorderBrush}" Height="36" CornerRadius="4"/> <Border Background="{DynamicResource SecondaryBorderBrush}" Height="36" CornerRadius="4"/>
</hc:Col> </hc:Col>
<hc:Col Layout="{extension:ColLayout Xs=4, Sm=6, Md=8, Lg=9, Xl=11}"> <hc:Col Layout="{hc:ColLayout Xs=4, Sm=6, Md=8, Lg=9, Xl=11}">
<Border Background="{DynamicResource BorderBrush}" Height="36" CornerRadius="4"/> <Border Background="{DynamicResource BorderBrush}" Height="36" CornerRadius="4"/>
</hc:Col> </hc:Col>
<hc:Col Layout="{extension:ColLayout Xs=8, Sm=6, Md=4, Lg=3, Xl=1}"> <hc:Col Layout="{hc:ColLayout Xs=8, Sm=6, Md=4, Lg=3, Xl=1}">
<Border Background="{DynamicResource SecondaryBorderBrush}" Height="36" CornerRadius="4"/> <Border Background="{DynamicResource SecondaryBorderBrush}" Height="36" CornerRadius="4"/>
</hc:Col> </hc:Col>
</hc:Row> </hc:Row>
@@ -9,7 +9,7 @@ namespace HandyControl.Controls;
public class Col : ContentControl public class Col : ContentControl
{ {
public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register( 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 public ColLayout Layout
{ {
@@ -18,7 +18,7 @@ public class Col : ContentControl
} }
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register( 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 public int Offset
{ {
@@ -27,12 +27,12 @@ public class Col : ContentControl
} }
public static readonly DependencyProperty SpanProperty = DependencyProperty.Register( 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) private static bool OnSpanValidate(object value)
{ {
var v = (int) value; var v = (int) value;
return v is >= 1 and <= 24; return v is >= 1 and <= ColLayout.ColMaxCellCount;
} }
public int Span public int Span
@@ -42,7 +42,7 @@ public class Col : ContentControl
} }
public static readonly DependencyProperty IsFixedProperty = DependencyProperty.Register( 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 public bool IsFixed
{ {
@@ -52,44 +52,26 @@ public class Col : ContentControl
internal int GetLayoutCellCount(ColLayoutStatus status) internal int GetLayoutCellCount(ColLayoutStatus status)
{ {
var result = 0; if (Layout is not null)
if (Layout != null)
{ {
if (!IsFixed) return status switch
{ {
switch (status) ColLayoutStatus.Xs => Layout.Xs,
{ ColLayoutStatus.Sm => Layout.Sm,
case ColLayoutStatus.Xs: ColLayoutStatus.Md => Layout.Md,
result = Layout.Xs; ColLayoutStatus.Lg => Layout.Lg,
break; ColLayoutStatus.Xl => Layout.Xl,
case ColLayoutStatus.Sm: ColLayoutStatus.Xxl => Layout.Xxl,
result = Layout.Sm; ColLayoutStatus.Auto => 0,
break; _ => throw new ArgumentOutOfRangeException(nameof(status), status, null),
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;
} }
return result; if (IsFixed)
{
return 0;
}
return Span;
} }
} }
@@ -14,12 +14,15 @@ public class Row : Panel
private double _maxChildDesiredHeight; private double _maxChildDesiredHeight;
private double _totalAutoWidth; private double _fixedWidth;
public static readonly DependencyProperty GutterProperty = DependencyProperty.Register( 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 public double Gutter
{ {
@@ -29,51 +32,59 @@ public class Row : Panel
protected override Size MeasureOverride(Size constraint) protected override Size MeasureOverride(Size constraint)
{ {
var gutter = Gutter;
var totalCellCount = 0; var totalCellCount = 0;
var totalRowCount = 1; var totalRowCount = 1;
var gutterHalf = Gutter / 2; _fixedWidth = 0;
_totalAutoWidth = 0; _maxChildDesiredHeight = 0;
var cols = InternalChildren.OfType<Col>().ToList();
foreach (var child in InternalChildren.OfType<Col>()) 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); var cellCount = child.GetLayoutCellCount(_layoutStatus);
totalCellCount += cellCount;
if (totalCellCount > ColLayout.ColMaxCellCount)
{
totalCellCount = cellCount;
totalRowCount++;
}
if (cellCount == 0 || child.IsFixed) 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) protected override Size ArrangeOverride(Size finalSize)
{ {
var gutter = Gutter;
var totalCellCount = 0; var totalCellCount = 0;
var gutterHalf = Gutter / 2; var cols = InternalChildren.OfType<Col>().ToList();
var itemWidth = (finalSize.Width - _totalAutoWidth + Gutter) / ColLayout.ColMaxCellCount; var itemWidth = (finalSize.Width - _fixedWidth + gutter) / ColLayout.ColMaxCellCount;
itemWidth = Math.Max(0, itemWidth); 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); _layoutStatus = ColLayout.GetLayoutStatus(finalSize.Width);
foreach (var child in InternalChildren.OfType<Col>()) foreach (var child in cols)
{ {
if (!child.IsVisible) if (!child.IsVisible)
{ {
@@ -83,19 +94,19 @@ public class Row : Panel
var cellCount = child.GetLayoutCellCount(_layoutStatus); var cellCount = child.GetLayoutCellCount(_layoutStatus);
totalCellCount += cellCount; 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.Width = childWidth;
childBounds.X += child.Offset * itemWidth; childBounds.X += child.Offset * itemWidth;
if (totalCellCount > ColLayout.ColMaxCellCount) if (totalCellCount > ColLayout.ColMaxCellCount)
{ {
childBounds.X = -gutterHalf; childBounds.X = 0;
childBounds.Y += _maxChildDesiredHeight; childBounds.Y += _maxChildDesiredHeight;
totalCellCount = cellCount; totalCellCount = cellCount;
} }
child.Arrange(childBounds); child.Arrange(childBounds);
childBounds.X += childWidth; childBounds.X += childWidth + gutter;
} }
return finalSize; return finalSize;
@@ -16,7 +16,7 @@
<hc:Col Layout="12" x:Name="ColStart"> <hc:Col Layout="12" x:Name="ColStart">
<Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square"/> <Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square"/>
</hc:Col> </hc:Col>
<hc:Col Layout="0"> <hc:Col IsFixed="True">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> <ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</hc:Col> </hc:Col>
<hc:Col Layout="12" x:Name="ColEnd"> <hc:Col Layout="12" x:Name="ColEnd">
@@ -60,4 +60,4 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>
@@ -8701,7 +8701,7 @@
<hc:Col Layout="12" x:Name="ColStart"> <hc:Col Layout="12" x:Name="ColStart">
<Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square" /> <Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square" />
</hc:Col> </hc:Col>
<hc:Col Layout="0"> <hc:Col IsFixed="True">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" /> <ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" />
</hc:Col> </hc:Col>
<hc:Col Layout="12" x:Name="ColEnd"> <hc:Col Layout="12" x:Name="ColEnd">
@@ -11,19 +11,19 @@ namespace HandyControl.Tools.Extension;
[TypeConverter(typeof(ColLayoutConverter))] [TypeConverter(typeof(ColLayoutConverter))]
public class ColLayout : MarkupExtension 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; public int Xs { get; set; } = 24;