add some demos

This commit is contained in:
NaBian 2019-10-25 01:13:16 +08:00
parent fa863c5bcb
commit 48920792f0
7 changed files with 113 additions and 22 deletions

View File

@ -1,8 +1,15 @@
<UserControl x:Class="HandyControlDemo.UserControl.DividerDemoCtl" <UserControl x:Class="HandyControlDemo.UserControl.DividerDemoCtl"
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"
Background="{DynamicResource RegionBrush}"> Background="{DynamicResource RegionBrush}">
<Grid> <hc:TransitioningContentControl>
<StackPanel Margin="32" Width="300">
</Grid> <hc:Divider/>
<hc:Divider Content="With Text"/>
<hc:Divider Content="With Text" Padding="10,0"/>
<hc:Divider LineStrokeThickness="2" LineStroke="{DynamicResource DarkPrimaryBrush}"/>
<hc:Divider LineStrokeDashArray="2,2"/>
</StackPanel>
</hc:TransitioningContentControl>
</UserControl> </UserControl>

View File

@ -1,4 +1,5 @@
using System.Windows; using System;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using HandyControl.Data; using HandyControl.Data;
using HandyControl.Tools.Extension; using HandyControl.Tools.Extension;
@ -66,6 +67,10 @@ namespace HandyControl.Controls
case ColLayoutStatus.Xxl: case ColLayoutStatus.Xxl:
result = Layout.Xxl; result = Layout.Xxl;
break; break;
case ColLayoutStatus.Auto:
break;
default:
throw new ArgumentOutOfRangeException(nameof(status), status, null);
} }
} }
else else

View File

@ -13,6 +13,8 @@ namespace HandyControl.Controls
private double _maxChildDesiredHeight; private double _maxChildDesiredHeight;
private double _totalAutoWidth;
public static readonly DependencyProperty GutterProperty = DependencyProperty.Register( public static readonly DependencyProperty GutterProperty = DependencyProperty.Register(
"Gutter", typeof(double), typeof(Row), new PropertyMetadata(ValueBoxes.Double0Box, null, OnGutterCoerce), ValidateHelper.IsInRangeOfPosDoubleIncludeZero); "Gutter", typeof(double), typeof(Row), new PropertyMetadata(ValueBoxes.Double0Box, null, OnGutterCoerce), ValidateHelper.IsInRangeOfPosDoubleIncludeZero);
@ -29,6 +31,7 @@ namespace HandyControl.Controls
var totalCellCount = 0; var totalCellCount = 0;
var totalRowCount = 1; var totalRowCount = 1;
var gutterHalf = Gutter / 2; var gutterHalf = Gutter / 2;
_totalAutoWidth = 0;
foreach (var child in InternalChildren.OfType<Col>()) foreach (var child in InternalChildren.OfType<Col>())
{ {
@ -40,12 +43,7 @@ namespace HandyControl.Controls
{ {
_maxChildDesiredHeight = childDesiredSize.Height; _maxChildDesiredHeight = childDesiredSize.Height;
} }
}
_layoutStatus = ColLayout.GetLayoutStatus(constraint.Width);
foreach (var child in InternalChildren.OfType<Col>())
{
var cellCount = child.GetLayoutCellCount(_layoutStatus); var cellCount = child.GetLayoutCellCount(_layoutStatus);
totalCellCount += cellCount; totalCellCount += cellCount;
@ -54,16 +52,21 @@ namespace HandyControl.Controls
totalCellCount = cellCount; totalCellCount = cellCount;
totalRowCount++; totalRowCount++;
} }
if (cellCount == 0)
{
_totalAutoWidth += childDesiredSize.Width;
}
} }
return new Size(0, _maxChildDesiredHeight * totalRowCount - Gutter); return new Size(constraint.Width, _maxChildDesiredHeight * totalRowCount - Gutter);
} }
protected override Size ArrangeOverride(Size finalSize) protected override Size ArrangeOverride(Size finalSize)
{ {
var totalCellCount = 0; var totalCellCount = 0;
var gutterHalf = Gutter / 2; var gutterHalf = Gutter / 2;
var itemWidth = (finalSize.Width + Gutter) / ColLayout.ColMaxCellCount; var itemWidth = (finalSize.Width - _totalAutoWidth + Gutter) / ColLayout.ColMaxCellCount;
var childBounds = new Rect(-gutterHalf, -gutterHalf, 0, _maxChildDesiredHeight); var childBounds = new Rect(-gutterHalf, -gutterHalf, 0, _maxChildDesiredHeight);
_layoutStatus = ColLayout.GetLayoutStatus(finalSize.Width); _layoutStatus = ColLayout.GetLayoutStatus(finalSize.Width);
@ -72,7 +75,8 @@ namespace HandyControl.Controls
var cellCount = child.GetLayoutCellCount(_layoutStatus); var cellCount = child.GetLayoutCellCount(_layoutStatus);
totalCellCount += cellCount; totalCellCount += cellCount;
var childWidth = cellCount * itemWidth; var childWidth = cellCount > 0 ? cellCount * itemWidth : 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)

View File

@ -1,5 +1,6 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
using HandyControl.Data; using HandyControl.Data;
namespace HandyControl.Controls namespace HandyControl.Controls
@ -11,19 +12,10 @@ namespace HandyControl.Controls
public object Content public object Content
{ {
get => (object) GetValue(ContentProperty); get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value); set => SetValue(ContentProperty, value);
} }
public static readonly DependencyProperty DashedProperty = DependencyProperty.Register(
"Dashed", typeof(bool), typeof(Divider), new PropertyMetadata(ValueBoxes.FalseBox));
public bool Dashed
{
get => (bool) GetValue(DashedProperty);
set => SetValue(DashedProperty, value);
}
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register( public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
"Orientation", typeof(Orientation), typeof(Divider), new PropertyMetadata(default(Orientation))); "Orientation", typeof(Orientation), typeof(Divider), new PropertyMetadata(default(Orientation)));
@ -32,5 +24,59 @@ namespace HandyControl.Controls
get => (Orientation) GetValue(OrientationProperty); get => (Orientation) GetValue(OrientationProperty);
set => SetValue(OrientationProperty, value); set => SetValue(OrientationProperty, value);
} }
public static readonly DependencyProperty ContentTemplateProperty = DependencyProperty.Register(
"ContentTemplate", typeof(DataTemplate), typeof(Divider), new PropertyMetadata(default(DataTemplate)));
public DataTemplate ContentTemplate
{
get => (DataTemplate) GetValue(ContentTemplateProperty);
set => SetValue(ContentTemplateProperty, value);
}
public static readonly DependencyProperty ContentStringFormatProperty = DependencyProperty.Register(
"ContentStringFormat", typeof(string), typeof(Divider), new PropertyMetadata(default(string)));
public string ContentStringFormat
{
get => (string) GetValue(ContentStringFormatProperty);
set => SetValue(ContentStringFormatProperty, value);
}
public static readonly DependencyProperty ContentTemplateSelectorProperty = DependencyProperty.Register(
"ContentTemplateSelector", typeof(DataTemplateSelector), typeof(Divider), new PropertyMetadata(default(DataTemplateSelector)));
public DataTemplateSelector ContentTemplateSelector
{
get => (DataTemplateSelector) GetValue(ContentTemplateSelectorProperty);
set => SetValue(ContentTemplateSelectorProperty, value);
}
public static readonly DependencyProperty LineStrokeProperty = DependencyProperty.Register(
"LineStroke", typeof(Brush), typeof(Divider), new PropertyMetadata(default(Brush)));
public Brush LineStroke
{
get => (Brush) GetValue(LineStrokeProperty);
set => SetValue(LineStrokeProperty, value);
}
public static readonly DependencyProperty LineStrokeThicknessProperty = DependencyProperty.Register(
"LineStrokeThickness", typeof(double), typeof(Divider), new PropertyMetadata(ValueBoxes.Double1Box));
public double LineStrokeThickness
{
get => (double) GetValue(LineStrokeThicknessProperty);
set => SetValue(LineStrokeThicknessProperty, value);
}
public static readonly DependencyProperty LineStrokeDashArrayProperty = DependencyProperty.Register(
"LineStrokeDashArray", typeof(DoubleCollection), typeof(Divider), new PropertyMetadata(new DoubleCollection()));
public DoubleCollection LineStrokeDashArray
{
get => (DoubleCollection) GetValue(LineStrokeDashArrayProperty);
set => SetValue(LineStrokeDashArrayProperty, value);
}
} }
} }

View File

@ -8,5 +8,6 @@
Lg, Lg,
Xl, Xl,
Xxl, Xxl,
Auto
} }
} }

View File

@ -4,6 +4,32 @@
<Style x:Key="DividerBaseStyle" TargetType="controls:Divider"> <Style x:Key="DividerBaseStyle" TargetType="controls:Divider">
<Setter Property="Focusable" Value="False"/> <Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="0, 24"/>
<Setter Property="Padding" Value="24, 0"/>
<Setter Property="LineStroke" Value="{DynamicResource BorderBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Divider">
<controls:Row>
<controls:Col Layout="12">
<Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square"/>
</controls:Col>
<controls:Col Layout="0">
<ContentPresenter Margin="{TemplateBinding Padding}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</controls:Col>
<controls:Col Layout="12">
<Line VerticalAlignment="Center" StrokeDashArray="{TemplateBinding LineStrokeDashArray}" Stroke="{TemplateBinding LineStroke}" X2="1" StrokeThickness="{TemplateBinding LineStrokeThickness}" Stretch="Fill" StrokeEndLineCap="Square" StrokeStartLineCap="Square"/>
</controls:Col>
</controls:Row>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Content" Value="{x:Null}">
<Setter Property="Padding" Value="0"/>
</Trigger>
</Style.Triggers>
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>

View File

@ -13,6 +13,8 @@ namespace HandyControl.Tools.Extension
{ {
public static readonly int ColMaxCellCount = 24; public static readonly int ColMaxCellCount = 24;
public static readonly int HalfColMaxCellCount = 12;
public static readonly int XsMaxWidth = 768; public static readonly int XsMaxWidth = 768;
public static readonly int SmMaxWidth = 992; public static readonly int SmMaxWidth = 992;