Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WrapStackPanel : Panel
- {
- protected override Size MeasureOverride(Size availableSize)
- {
- var width = availableSize.Width >= 501 ? availableSize.Width / 2d : availableSize.Width;
- var height1 = 0d;
- var height2 = 0d;
- for (int i = 0; i < Children.Count; i++)
- {
- var child = Children[i];
- child.Measure(new Size(width, double.PositiveInfinity));
- if (i % 2 == 1 && availableSize.Width >= 501)
- {
- height2 += child.DesiredSize.Height;
- }
- else
- {
- height1 += child.DesiredSize.Height;
- }
- }
- return new Size(availableSize.Width, Math.Max(height1, height2));
- }
- protected override Size ArrangeOverride(Size finalSize)
- {
- var width = finalSize.Width >= 501 ? finalSize.Width / 2d : finalSize.Width;
- var height1 = 0d;
- var height2 = 0d;
- for (int i = 0; i < Children.Count; i++)
- {
- var child = Children[i];
- var x = (i % 2 == 1 && finalSize.Width >= 501) ? width : 0;
- var y = (i % 2 == 1 && finalSize.Width >= 501) ? height2 : height1;
- child.Arrange(new Rect(x, y, width, child.DesiredSize.Height));
- if (i % 2 == 1 && finalSize.Width >= 501)
- {
- height2 += child.DesiredSize.Height;
- }
- else
- {
- height1 += child.DesiredSize.Height;
- }
- }
- return new Size(finalSize.Width, Math.Max(height1, height2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement