diff --git a/README.md b/README.md index 7c5f1c52..29fc1921 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ Step 3:enjoy coding ## Latest examples +### Grid + +![Grid](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/Grid.gif) + ### SideMenu ![SideMenu](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/SideMenu.png) @@ -70,12 +74,12 @@ Step 3:enjoy coding ![WaveProgressBar](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/WaveProgressBar.gif) +## History publication + ### Badge ![Badge](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/Badge.png) -## History publication - ### Gravatar ![Gravatar](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/Gravatar.gif) diff --git a/Resources/Grid.gif b/Resources/Grid.gif new file mode 100644 index 00000000..9041b842 Binary files /dev/null and b/Resources/Grid.gif differ diff --git a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj index fdbd815d..f4e0039c 100644 --- a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj +++ b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj @@ -315,6 +315,9 @@ Resources\Img\LeftMainContent\WindowsForm_16x.png + + Resources\Img\LeftMainContent\GridPane_16x.png + Resources\Img\qq-group.jpg diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj index 4e282a0d..f6f98c80 100644 --- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj +++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj @@ -395,6 +395,9 @@ TextTemplatingFileGenerator MessageToken.cs + + Resources\Img\LeftMainContent\GridPane_16x.png + Resources\Img\LeftMainContent\MainMenuControl_16x.png diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs index 9d91fd32..6247b2cb 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs @@ -114,6 +114,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 基础布局 的本地化字符串。 + /// + public static string BasicLayout { + get { + return ResourceManager.GetString("BasicLayout", resourceCulture); + } + } + /// /// 查找类似 闪烁 的本地化字符串。 /// @@ -135,9 +144,9 @@ namespace HandyControlDemo.Properties.Langs { /// /// 查找类似 边框 的本地化字符串。 /// - public static string Border1 { + public static string Border { get { - return ResourceManager.GetString("Border1", resourceCulture); + return ResourceManager.GetString("Border", resourceCulture); } } @@ -276,6 +285,24 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 分栏偏移 的本地化字符串。 + /// + public static string ColumnOffset { + get { + return ResourceManager.GetString("ColumnOffset", resourceCulture); + } + } + + /// + /// 查找类似 分栏间隔 的本地化字符串。 + /// + public static string ColumnSpacing { + get { + return ResourceManager.GetString("ColumnSpacing", resourceCulture); + } + } + /// /// 查找类似 组合框 的本地化字符串。 /// @@ -627,6 +654,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 混合布局 的本地化字符串。 + /// + public static string HybridLayout { + get { + return ResourceManager.GetString("HybridLayout", resourceCulture); + } + } + /// /// 查找类似 忽略 的本地化字符串。 /// @@ -1086,6 +1122,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 响应式布局 的本地化字符串。 + /// + public static string ResponsiveLayout { + get { + return ResourceManager.GetString("ResponsiveLayout", resourceCulture); + } + } + /// /// 查找类似 富文本框 的本地化字符串。 /// diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx index 9807ecb7..2705cc41 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx @@ -309,9 +309,6 @@ TreeView - - Border - ScrollViewer @@ -585,4 +582,22 @@ Grid + + Basic layout + + + Column spacing + + + Hybrid layout + + + Column offset + + + Responsive layout + + + Border + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx index 0f5ce9d5..d10f5ec2 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx @@ -309,7 +309,7 @@ 树视图 - + 边框 @@ -585,4 +585,19 @@ 栅格 + + 基础布局 + + + 分栏间隔 + + + 混合布局 + + + 分栏偏移 + + + 响应式布局 + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml index 5c0b25d0..f07af0f9 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml @@ -3,57 +3,153 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl" xmlns:extension="clr-namespace:HandyControl.Tools.Extension;assembly=HandyControl" + xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs" Background="{DynamicResource RegionBrush}"> - - - + + + + - - + + + + - - + + - - + + + + - - + + - - + + - - + + + + - - + + - - + + - - + + - - + + + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml index a949e809..49b8368a 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml @@ -161,7 +161,7 @@ - + diff --git a/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs b/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs index 8676c2f8..1a77bc96 100644 --- a/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs +++ b/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs @@ -8,7 +8,7 @@ namespace HandyControl.Controls public class Col : ContentControl { public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register( - "Layout", typeof(ColLayout), typeof(Col), new PropertyMetadata(new ColLayout())); + "Layout", typeof(ColLayout), typeof(Col), new PropertyMetadata(default(ColLayout))); public ColLayout Layout { @@ -17,7 +17,7 @@ namespace HandyControl.Controls } public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register( - "Offset", typeof(int), typeof(Col), new PropertyMetadata(default(int))); + "Offset", typeof(int), typeof(Col), new PropertyMetadata(ValueBoxes.Int0Box)); public int Offset { @@ -25,18 +25,55 @@ namespace HandyControl.Controls set => SetValue(OffsetProperty, value); } + public static readonly DependencyProperty SpanProperty = DependencyProperty.Register( + "Span", typeof(int), typeof(Col), new PropertyMetadata(24), OnSpanValidate); + + private static bool OnSpanValidate(object value) + { + var v = (int)value; + return v >= 1 || v <= 24; + } + + public int Span + { + get => (int) GetValue(SpanProperty); + set => SetValue(SpanProperty, value); + } + internal int GetLayoutCellCount(ColLayoutStatus status) { - switch (status) + var result = 0; + + if (Layout != null) { - 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; + 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; + } } + else + { + result = Span; + } + + return result; } } } diff --git a/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs b/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs index 4b2e1e8c..155ed71b 100644 --- a/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs +++ b/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; using HandyControl.Data; +using HandyControl.Tools; namespace HandyControl.Controls { @@ -10,8 +11,14 @@ namespace HandyControl.Controls { private ColLayoutStatus _layoutStatus; + private double _maxChildDesiredHeight; + public static readonly DependencyProperty GutterProperty = DependencyProperty.Register( - "Gutter", typeof(double), typeof(Row), new PropertyMetadata(default(double))); + "Gutter", typeof(double), typeof(Row), new PropertyMetadata(ValueBoxes.Double0Box, null, OnGutterCoerce), OnGutterValidate); + + private static object OnGutterCoerce(DependencyObject d, object basevalue) => OnGutterValidate(basevalue) ? basevalue : .0; + + private static bool OnGutterValidate(object value) => ValidateHelper.IsInRangeOfPosDouble(value, true); public double Gutter { @@ -21,25 +28,24 @@ namespace HandyControl.Controls protected override Size MeasureOverride(Size constraint) { - var itemWidth = constraint.Width / ColLayout.ColMaxCellCount; var totalCellCount = 0; var totalRowCount = 1; - var maxChildDesiredHeight = .0; + var gutterHalf = Gutter / 2; - for (int i = 0, count = InternalChildren.Count; i < count; ++i) + foreach (var child in InternalChildren.OfType()) { - var child = InternalChildren[i]; - + child.Margin = new Thickness(gutterHalf); child.Measure(constraint); var childDesiredSize = child.DesiredSize; - if (maxChildDesiredHeight < childDesiredSize.Height) + if (_maxChildDesiredHeight < childDesiredSize.Height) { - maxChildDesiredHeight = childDesiredSize.Height; + _maxChildDesiredHeight = childDesiredSize.Height; } } - var childBounds = new Rect(0, 0, 0, maxChildDesiredHeight); + var itemWidth = constraint.Width / ColLayout.ColMaxCellCount; + var childBounds = new Rect(-gutterHalf, -gutterHalf, 0, _maxChildDesiredHeight); _layoutStatus = ColLayout.GetLayoutStatus(constraint.Width); foreach (var child in InternalChildren.OfType()) @@ -49,19 +55,48 @@ namespace HandyControl.Controls if (totalCellCount > ColLayout.ColMaxCellCount) { - childBounds.X = 0; - childBounds.Y += maxChildDesiredHeight; + childBounds.X = -gutterHalf; + childBounds.Y += _maxChildDesiredHeight; totalCellCount = cellCount; totalRowCount++; } var childWidth = cellCount * itemWidth; childBounds.Width = childWidth; + childBounds.X += childWidth + child.Offset * itemWidth; + } + + return new Size(0, _maxChildDesiredHeight * totalRowCount - Gutter); + } + + protected override Size ArrangeOverride(Size finalSize) + { + var totalCellCount = 0; + var gutterHalf = Gutter / 2; + var itemWidth = (finalSize.Width + Gutter) / ColLayout.ColMaxCellCount; + var childBounds = new Rect(-gutterHalf, -gutterHalf, 0, _maxChildDesiredHeight); + _layoutStatus = ColLayout.GetLayoutStatus(finalSize.Width); + + foreach (var child in InternalChildren.OfType()) + { + var cellCount = child.GetLayoutCellCount(_layoutStatus); + totalCellCount += cellCount; + + var childWidth = cellCount * itemWidth; + childBounds.Width = childWidth; + childBounds.X += child.Offset * itemWidth; + if (totalCellCount > ColLayout.ColMaxCellCount) + { + childBounds.X = -gutterHalf; + childBounds.Y += _maxChildDesiredHeight; + totalCellCount = cellCount; + } + child.Arrange(childBounds); childBounds.X += childWidth; } - return new Size(constraint.Width, maxChildDesiredHeight * totalRowCount); + return finalSize; } } } diff --git a/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs b/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs index 054dd802..e9e4a87e 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/AnimationPath.cs @@ -15,7 +15,7 @@ namespace HandyControl.Controls private bool _isLoaded; /// - /// 故事版 + /// 故事板 /// private Storyboard _storyboard; diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/ValidateHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/ValidateHelper.cs index 4a0a94a6..ff69c094 100644 --- a/src/Shared/HandyControl_Shared/Tools/Helper/ValidateHelper.cs +++ b/src/Shared/HandyControl_Shared/Tools/Helper/ValidateHelper.cs @@ -29,7 +29,7 @@ } /// - /// 是否在正浮点数范围内 + /// 是否在负浮点数范围内 /// /// ///