I have two functions, horizontal and vertical, for laying out controls. They work like this:
let verticalList = vertical [new TextBlock(Text = "one");
new TextBlock(Text = "two");
new TextBlock(Text = "three")]
Now verticalList is a control that displays the three textblocks vertically:
one
two
three
Here are the definitions:
let horizontal controls =
let wrap = new WrapPanel() in
List.iter (wrap.Children.Add >> ignore) controls ;
wrap
let vertical controls =
let stack = new StackPanel() in
List.iter (stack.Children.Add >> ignore) controls ;
stack
A problem occurs when I combine different types:
let foo = vertical [new TextBlock(Text = "Title"); vertical items]
This complains that the elements of the list are not of the same type. That is true, but they have a common supertype (UIElement).
I know I can use :> UIElement to upcast both items in the list, but this is an ugly solution. Can F# infer the common supertype. If not, why not?
It would be great if the nice looking
vertical [X; Y; Z]
doesn't have to become
vertical [(X :> UIElement); (Y :> UIElement); (Z :> UIElement)]