1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
|
type WrapPanel() =
inherit Panel()
override x.MeasureOverride(availableSize:Size) =
let childMeasure = Size(Double.PositiveInfinity, Double.PositiveInfinity)
let _, (width,height) =
x.Children
|> Seq.fold (fun ((x, y), (width, height)) child ->
child.Measure(childMeasure)
if child.DesiredSize.Width + x > availableSize.Width
then (child.DesiredSize.Width, 0.0), (max x width, height + y)
else (x + child.DesiredSize.Width, y), (width, height)
) ((0.0,0.0),(0.0,0.0))
Size(width, height)
override x.ArrangeOverride(finalSize:Size) =
x.Children
|> Seq.fold (fun (x,y,height) child ->
let x,y,height =
if child.DesiredSize.Width + x > finalSize.Width
then 0.0, y + height, 0.0
else x, y, height
Rect(x, y, child.DesiredSize.Width, child.DesiredSize.Height)
|> child.Arrange
x + child.DesiredSize.Width, y, max height child.DesiredSize.Height
) (0.0,0.0,0.0)
|> ignore
finalSize
|