This commit is contained in:
NaBian committed 2019-05-08 00:15:19 +08:00
1 parent 467bedb656
commit a0707147ae
20 files changed
+314 -24

No files matched your search

@@ -0,0 +1,42 @@
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
using HandyControl.Tools.Extension;
namespace HandyControl.Controls
{
public class Col : ContentControl
{
public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register(
"Layout", typeof(ColLayout), typeof(Col), new PropertyMetadata(new ColLayout()));
public ColLayout Layout
{
get => (ColLayout)GetValue(LayoutProperty);
set => SetValue(LayoutProperty, value);
}
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register(
"Offset", typeof(int), typeof(Col), new PropertyMetadata(default(int)));
public int Offset
{
get => (int)GetValue(OffsetProperty);
set => SetValue(OffsetProperty, value);
}
internal int GetLayoutCellCount(ColLayoutStatus status)
{
switch (status)
{
case ColLayoutStatus.Xs: return Layout.Xs;
case ColLayoutStatus.Sm: return Layout.Sm;
case ColLayoutStatus.Md: return Layout.Md;
case ColLayoutStatus.Lg: return Layout.Lg;
case ColLayoutStatus.Xl: return Layout.Xl;
case ColLayoutStatus.Xxl: return Layout.Xxl;
default: return 0;
}
}
}
}
@@ -0,0 +1,67 @@
using HandyControl.Tools.Extension;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Controls
{
public class Row : Panel
{
private ColLayoutStatus _layoutStatus;
public static readonly DependencyProperty GutterProperty = DependencyProperty.Register(
"Gutter", typeof(double), typeof(Row), new PropertyMetadata(default(double)));
public double Gutter
{
get => (double)GetValue(GutterProperty);
set => SetValue(GutterProperty, value);
}
protected override Size MeasureOverride(Size constraint)
{
var itemWidth = constraint.Width / ColLayout.ColMaxCellCount;
var totalCellCount = 0;
var totalRowCount = 1;
var maxChildDesiredHeight = .0;
for (int i = 0, count = InternalChildren.Count; i < count; ++i)
{
var child = InternalChildren[i];
child.Measure(constraint);
var childDesiredSize = child.DesiredSize;
if (maxChildDesiredHeight < childDesiredSize.Height)
{
maxChildDesiredHeight = childDesiredSize.Height;
}
}
var childBounds = new Rect(0, 0, 0, maxChildDesiredHeight);
_layoutStatus = ColLayout.GetLayoutStatus(constraint.Width);
foreach (var child in InternalChildren.OfType<Col>())
{
var cellCount = child.GetLayoutCellCount(_layoutStatus);
totalCellCount += cellCount;
if (totalCellCount > ColLayout.ColMaxCellCount)
{
childBounds.X = 0;
childBounds.Y += maxChildDesiredHeight;
totalCellCount = cellCount;
totalRowCount++;
}
var childWidth = cellCount * itemWidth;
childBounds.Width = childWidth;
child.Arrange(childBounds);
childBounds.X += childWidth;
}
return new Size(constraint.Width, maxChildDesiredHeight * totalRowCount);
}
}
}
@@ -1,9 +0,0 @@
using System.Windows.Controls;
namespace HandyControl.Controls
{
public class Col : Panel
{
}
}
@@ -1,9 +0,0 @@
using System.Windows.Controls;
namespace HandyControl.Controls
{
public class Row : Panel
{
}
}