tags:

views:

133

answers:

4

well what i want is this lets say i have a "panel" with the width 100 and height 100

now i want to place X objects witht the size 20 so when i add more 5 items it should have all items on one line

|Item1|Item2|Item3|Item4|Item5|

now if i would add one more then i want it to split it to 2 lines with 3 items on each row

|Item1|Item2|Item3|

|Item4|Item5|Item6|

and well i guess you get the point, iv tryed stack panel but i cant get it to work the way i want it to..

Edit:

well it doesnt matter that mutch if each row has an equal amount of items.. so a wrapPanel should do the job next problem -> Here

A: 

I don't think you will be able to get a container control that does that automatically. You could have a Grid with two rows and a StackPanel in each row. As you add the items you would need to programmatically select which StackPanel to put each item into.

sipwiz
+1  A: 

The WrapPanel should suit your needs:

Controls are positioned in either a stack or row based on the Orientation property. In addition to stacking, the WrapPanel provides wrapping support for contained controls. Thus if more controls are added to a WrapPanel than can be displayed by the width of the WrapPanel, they are wrapped around to form an additional stack or row.

To be honest, I haven't tried that specific requirement myself.

Razzie
Close, but the WrapPanel will only wrap the last item that doesn't fit - not the group of three.
Kent Boogaart
True, I missed that part in the question to be honest. I hope it is close enough!
Razzie
+1  A: 

I guess you could use WrapPanel... but then you would get 2 lines, (5 items and 1 item)..

What would happen if you had, say.. 7 items?

Arcturus
+2  A: 

There's no standard WPF panel that will do this for you. The WrapPanel comes close, but it will not make sure that your rows are even. Your best bet is to implement your own panel. Here's a good example on codeproject

dustyburwell