2025-08-15 15:33:20 +08:00

53 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Windows;
using System.Windows.Controls;
namespace SWS.CustomControl
{
/// <summary>
/// 当不需要使用Grid的分行分列则可使用 SmallPanel
/// </summary>
public class SmallPanel : Panel
{
/// <summary>
/// Content measurement.
/// </summary>
/// <param name="constraint">Constraint</param>
/// <returns>Desired size</returns>
protected override Size MeasureOverride(Size constraint)
{
Size gridDesiredSize = new Size();
UIElementCollection children = InternalChildren;
for (int i = 0, count = children.Count; i < count; ++i)
{
UIElement child = children[i];
if (child != null)
{
child.Measure(constraint);
gridDesiredSize.Width = Math.Max(gridDesiredSize.Width, child.DesiredSize.Width);
gridDesiredSize.Height = Math.Max(gridDesiredSize.Height, child.DesiredSize.Height);
}
}
return (gridDesiredSize);
}
/// <summary>
/// Content arrangement.
/// </summary>
/// <param name="arrangeSize">Arrange size</param>
protected override Size ArrangeOverride(Size arrangeSize)
{
UIElementCollection children = InternalChildren;
for (int i = 0, count = children.Count; i < count; ++i)
{
UIElement child = children[i];
if (child != null)
{
child.Arrange(new Rect(arrangeSize));
}
}
return (arrangeSize);
}
}
}