3 people like it.

WrapPanel

Positions child elements in sequential position from left to right, breaking content to the next line at the edge of the containing box. Tryable at http://tryfsharp.org

WrapPanel control

 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
Multiple items
type WrapPanel =
  inherit obj
  new : unit -> WrapPanel
  override ArrangeOverride : finalSize:'a -> 'b
  override MeasureOverride : availableSize:'a -> 'b

Full name: Script.WrapPanel

--------------------
new : unit -> WrapPanel
override WrapPanel.MeasureOverride : availableSize:'a -> 'b

Full name: Script.WrapPanel.MeasureOverride
type Double =
  struct
    member CompareTo : value:obj -> int + 1 overload
    member Equals : obj:obj -> bool + 1 overload
    member GetHashCode : unit -> int
    member GetTypeCode : unit -> TypeCode
    member ToString : unit -> string + 3 overloads
    static val MinValue : float
    static val MaxValue : float
    static val Epsilon : float
    static val NegativeInfinity : float
    static val PositiveInfinity : float
    ...
  end

Full name: System.Double
field float.PositiveInfinity = Infinity
module Seq

from Microsoft.FSharp.Collections
val fold : folder:('State -> 'T -> 'State) -> state:'State -> source:seq<'T> -> 'State

Full name: Microsoft.FSharp.Collections.Seq.fold
Multiple items
type MeasureAttribute =
  inherit Attribute
  new : unit -> MeasureAttribute

Full name: Microsoft.FSharp.Core.MeasureAttribute

--------------------
new : unit -> MeasureAttribute
val max : e1:'T -> e2:'T -> 'T (requires comparison)

Full name: Microsoft.FSharp.Core.Operators.max
override WrapPanel.ArrangeOverride : finalSize:'a -> 'b

Full name: Script.WrapPanel.ArrangeOverride
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/aJ
Posted:12 years ago
Author:Phillip Trelford
Tags: silverlight , control