mirror of
https://gitee.com/handyorg/HandyControl.git
synced 2024-11-30 02:48:03 +08:00
add SimpleStackPanel
This commit is contained in:
parent
6a4fb7afbf
commit
f1c687d7f9
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class SimpleStackPanel : Panel
|
||||
{
|
||||
public static readonly DependencyProperty OrientationProperty =
|
||||
StackPanel.OrientationProperty.AddOwner(typeof(SimpleStackPanel),
|
||||
new FrameworkPropertyMetadata(Orientation.Vertical, FrameworkPropertyMetadataOptions.AffectsMeasure));
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => (Orientation) GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
var stackDesiredSize = new Size();
|
||||
var children = InternalChildren;
|
||||
var layoutSlotSize = constraint;
|
||||
|
||||
if (Orientation == Orientation.Horizontal)
|
||||
{
|
||||
layoutSlotSize.Width = double.PositiveInfinity;
|
||||
|
||||
for (int i = 0, count = children.Count; i < count; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if (child == null) continue;
|
||||
|
||||
child.Measure(layoutSlotSize);
|
||||
var childDesiredSize = child.DesiredSize;
|
||||
|
||||
stackDesiredSize.Width += childDesiredSize.Width;
|
||||
stackDesiredSize.Height = Math.Max(stackDesiredSize.Height, childDesiredSize.Height);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
layoutSlotSize.Height = double.PositiveInfinity;
|
||||
|
||||
for (int i = 0, count = children.Count; i < count; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if (child == null) continue;
|
||||
|
||||
child.Measure(layoutSlotSize);
|
||||
var childDesiredSize = child.DesiredSize;
|
||||
|
||||
stackDesiredSize.Width = Math.Max(stackDesiredSize.Width, childDesiredSize.Width);
|
||||
stackDesiredSize.Height += childDesiredSize.Height;
|
||||
}
|
||||
}
|
||||
|
||||
return stackDesiredSize;
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size arrangeSize)
|
||||
{
|
||||
var children = InternalChildren;
|
||||
var rcChild = new Rect(arrangeSize);
|
||||
var previousChildSize = 0.0;
|
||||
|
||||
if (Orientation == Orientation.Horizontal)
|
||||
{
|
||||
for (int i = 0, count = children.Count; i < count; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if (child == null) continue;
|
||||
|
||||
rcChild.X += previousChildSize;
|
||||
previousChildSize = child.DesiredSize.Width;
|
||||
rcChild.Width = previousChildSize;
|
||||
rcChild.Height = Math.Max(arrangeSize.Height, child.DesiredSize.Height);
|
||||
|
||||
child.Arrange(rcChild);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0, count = children.Count; i < count; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if (child == null) continue;
|
||||
|
||||
rcChild.Y += previousChildSize;
|
||||
previousChildSize = child.DesiredSize.Height;
|
||||
rcChild.Height = previousChildSize;
|
||||
rcChild.Width = Math.Max(arrangeSize.Width, child.DesiredSize.Width);
|
||||
|
||||
child.Arrange(rcChild);
|
||||
}
|
||||
}
|
||||
|
||||
return arrangeSize;
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Poptip.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Watermark.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\FlexPanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\SimpleStackPanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\ImagePropertyEditor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\VerticalAlignmentPropertyEditor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\HorizontalAlignmentPropertyEditor.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user