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 18538671..37f8abfd 100644 --- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj +++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj @@ -414,6 +414,9 @@ TextTemplatingFileGenerator MessageToken.cs + + Resources\Img\LeftMainContent\GridPane_16x.png + Resources\Img\DevOps\DevOps-Boards.png diff --git a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs index c354f6be..d5fce6b2 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs +++ b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs @@ -94,6 +94,8 @@ public static readonly string SideMenuDemoCtl = nameof(SideMenuDemoCtl); + public static readonly string GridDemoCtl = nameof(GridDemoCtl); + public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl); public static readonly string RepeatButtonDemoCtl = nameof(RepeatButtonDemoCtl); diff --git a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt index d2b78d87..5117bc00 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt +++ b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt @@ -49,7 +49,8 @@ var controlList = new List "BadgeDemoCtl", "GravatarDemoCtl", "DialogDemoCtl", - "SideMenuDemoCtl" + "SideMenuDemoCtl", + "GridDemoCtl" }; var styleList = new List { diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems index 79aecd24..7a9d0ef9 100644 --- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems +++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems @@ -38,6 +38,7 @@ ChatBox.xaml + InteractiveDialog.xaml @@ -74,6 +75,9 @@ CompareSliderDemoCtl.xaml + + GridDemoCtl.xaml + CoverFlowDemoCtl.xaml @@ -420,6 +424,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs index 61421dcd..9d91fd32 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs @@ -528,6 +528,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 栅格 的本地化字符串。 + /// + public static string Grid { + get { + return ResourceManager.GetString("Grid", resourceCulture); + } + } + /// /// 查找类似 分组框 的本地化字符串。 /// diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx index 9ed862a8..9807ecb7 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx @@ -582,4 +582,7 @@ Overview + + Grid + \ 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 d83c268e..0f5ce9d5 100644 --- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx +++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx @@ -582,4 +582,7 @@ 概览 + + 栅格 + \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/GridPane_16x.png b/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/GridPane_16x.png new file mode 100644 index 00000000..51285602 Binary files /dev/null and b/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/GridPane_16x.png differ diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Basic/IFull.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Basic/IFull.cs new file mode 100644 index 00000000..dede1433 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Basic/IFull.cs @@ -0,0 +1,7 @@ +namespace HandyControlDemo.UserControl +{ + internal interface IFull + { + + } +} \ 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 new file mode 100644 index 00000000..5c0b25d0 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml.cs new file mode 100644 index 00000000..2054b682 --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/GridDemoCtl.xaml.cs @@ -0,0 +1,10 @@ +namespace HandyControlDemo.UserControl +{ + public partial class GridDemoCtl : IFull + { + public GridDemoCtl() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml index 1cc52d85..a949e809 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/LeftMainContent.xaml @@ -200,7 +200,7 @@ - + @@ -315,6 +315,11 @@ + + + + + diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs index 3e36ccf0..c2d992cb 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Main/MainViewModel.cs @@ -9,6 +9,7 @@ using GalaSoft.MvvmLight.Messaging; using HandyControlDemo.Data; using HandyControlDemo.Service; using HandyControlDemo.Tools; +using HandyControlDemo.UserControl; namespace HandyControlDemo.ViewModel { @@ -114,9 +115,10 @@ namespace HandyControlDemo.ViewModel if (Equals(_listBoxItemCurrent, item)) return; _listBoxItemCurrent = item; ContentTitle = item.Content; - Messenger.Default.Send(false, MessageToken.FullSwitch); var obj = AssemblyHelper.ResolveByKey(tag); - Messenger.Default.Send(obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{tag}"), MessageToken.LoadShowContent); + var ctl = obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{tag}"); + Messenger.Default.Send(ctl is IFull, MessageToken.FullSwitch); + Messenger.Default.Send(ctl, MessageToken.LoadShowContent); } else { diff --git a/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs b/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs new file mode 100644 index 00000000..8676c2f8 --- /dev/null +++ b/src/Shared/HandyControl_Shared/Controls/Grid/Col.cs @@ -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; + } + } + } +} diff --git a/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs b/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs new file mode 100644 index 00000000..4b2e1e8c --- /dev/null +++ b/src/Shared/HandyControl_Shared/Controls/Grid/Row.cs @@ -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()) + { + 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); + } + } +} diff --git a/src/Shared/HandyControl_Shared/Controls/Panel/Col.cs b/src/Shared/HandyControl_Shared/Controls/Panel/Col.cs deleted file mode 100644 index bb401174..00000000 --- a/src/Shared/HandyControl_Shared/Controls/Panel/Col.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Windows.Controls; - -namespace HandyControl.Controls -{ - public class Col : Panel - { - - } -} \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Controls/Panel/Row.cs b/src/Shared/HandyControl_Shared/Controls/Panel/Row.cs deleted file mode 100644 index 6e2bc0ac..00000000 --- a/src/Shared/HandyControl_Shared/Controls/Panel/Row.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Windows.Controls; - -namespace HandyControl.Controls -{ - public class Row : Panel - { - - } -} \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Data/Enum/ColLayoutStatus.cs b/src/Shared/HandyControl_Shared/Data/Enum/ColLayoutStatus.cs new file mode 100644 index 00000000..5deda29f --- /dev/null +++ b/src/Shared/HandyControl_Shared/Data/Enum/ColLayoutStatus.cs @@ -0,0 +1,12 @@ +namespace HandyControl.Data +{ + public enum ColLayoutStatus + { + Xs, + Sm, + Md, + Lg, + Xl, + Xxl, + } +} \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index a237c220..7006f532 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -40,6 +40,8 @@ + + @@ -72,8 +74,6 @@ - - @@ -114,6 +114,7 @@ + @@ -219,6 +220,7 @@ + diff --git a/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs b/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs new file mode 100644 index 00000000..f0573647 --- /dev/null +++ b/src/Shared/HandyControl_Shared/Tools/Extension/ColLayout.cs @@ -0,0 +1,71 @@ +using System; +using System.Windows.Markup; +using HandyControl.Data; + +namespace HandyControl.Tools.Extension +{ + public class ColLayout : MarkupExtension + { + public static readonly int ColMaxCellCount = 24; + + public static readonly int XsMaxWidth = 768; + + public static readonly int SmMaxWidth = 992; + + public static readonly int MdMaxWidth = 1200; + + public static readonly int LgMaxWidth = 1920; + + public static readonly int XlMaxWidth = 2560; + + public int Xs { get; set; } = 24; + + public int Sm { get; set; } = 12; + + public int Md { get; set; } = 8; + + public int Lg { get; set; } = 6; + + public int Xl { get; set; } = 4; + + public int Xxl { get; set; } = 2; + + public override object ProvideValue(IServiceProvider serviceProvider) + { + return new ColLayout + { + Xs = Xs, + Sm = Sm, + Md = Md, + Lg = Lg, + Xl = Xl, + Xxl = Xxl + }; + } + + public static ColLayoutStatus GetLayoutStatus(double width) + { + if (width < MdMaxWidth) + { + if (width < SmMaxWidth) + { + if (width < XsMaxWidth) + { + return ColLayoutStatus.Xs; + } + return ColLayoutStatus.Sm; + } + return ColLayoutStatus.Md; + } + if (width < XlMaxWidth) + { + if (width < LgMaxWidth) + { + return ColLayoutStatus.Lg; + } + return ColLayoutStatus.Xl; + } + return ColLayoutStatus.Xxl; + } + } +} \ No newline at end of file