提交 81ddae5f 编写于 作者: N NaBian

fix: close #1374

上级 4206bfd6
......@@ -8582,7 +8582,7 @@
<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" />
</hc:Col>
<hc:Col Layout="0">
<hc:Col IsFixed="True">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" />
</hc:Col>
<hc:Col Layout="12" x:Name="ColEnd">
......
......@@ -5,7 +5,7 @@
<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>
<ApplicationIcon>..\..\Shared\HandyControlDemo_Shared\Resources\Img\icon.ico</ApplicationIcon>
<NoWarn>0108;MSB3026;MSB3061</NoWarn>
<NoWarn>0108;MSB3026;MSB3061;SYSLIB0014</NoWarn>
<MSBuildWarningsAsMessages>NETSDK1138</MSBuildWarningsAsMessages>
<ApplicationManifest>..\..\Shared\HandyControlDemo_Shared\app.manifest</ApplicationManifest>
</PropertyGroup>
......
......@@ -6,7 +6,7 @@
<Description>Contains some simple and commonly used WPF controls</Description>
<PackageId>HandyControl</PackageId>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>0067;0649;1591;MSB3061;SYSLIB0003;SYSLIB0004</NoWarn>
<NoWarn>0067;0649;1591;MSB3061;SYSLIB0003;SYSLIB0004;SYSLIB0032</NoWarn>
<MSBuildWarningsAsMessages>NETSDK1138</MSBuildWarningsAsMessages>
<AssemblyOriginatorKeyFile>..\..\Shared\HandyControl_Shared\key.snk</AssemblyOriginatorKeyFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
......
......@@ -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 @@
<hc:Col Layout="4 6 8 9 11">
<Border Background="{DynamicResource SecondaryBorderBrush}" Height="36" CornerRadius="4"/>
</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"/>
</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"/>
</hc:Col>
</hc:Row>
......
......@@ -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);
}
}
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),
};
}
else
if (IsFixed)
{
result = Span;
return 0;
}
return result;
return Span;
}
}
......@@ -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<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);
totalCellCount += cellCount;
if (totalCellCount > ColLayout.ColMaxCellCount)
if (cellCount == 0 || child.IsFixed)
{
totalCellCount = cellCount;
totalRowCount++;
child.Measure(constraint);
_maxChildDesiredHeight = Math.Max(_maxChildDesiredHeight, child.DesiredSize.Height);
_fixedWidth += child.DesiredSize.Width + gutter;
}
}
if (cellCount == 0 || child.IsFixed)
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)
{
_totalAutoWidth += childDesiredSize.Width;
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 - Gutter);
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<Col>().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<Col>())
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;
......
......@@ -16,7 +16,7 @@
<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"/>
</hc:Col>
<hc:Col Layout="0">
<hc:Col IsFixed="True">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</hc:Col>
<hc:Col Layout="12" x:Name="ColEnd">
......@@ -60,4 +60,4 @@
</Style.Triggers>
</Style>
</ResourceDictionary>
\ No newline at end of file
</ResourceDictionary>
......@@ -8701,7 +8701,7 @@
<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" />
</hc:Col>
<hc:Col Layout="0">
<hc:Col IsFixed="True">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" />
</hc:Col>
<hc:Col Layout="12" x:Name="ColEnd">
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册