views:

44

answers:

2

I have a container whose size can change.

I will by dynamically creating instances of a user control and adding them to that container. the size of the user control is fixed. what I want to do is, fit the most number of user controls in the container.

I think a good approach is to add the children horizontally until there is no more space to add another and then start another row.

Say, each row fits 3 children for a given width of the container. if it is expanded enough, it should automatically fit 4 children in a row.

Is there a container control (StackPanel Grid etc.) that I can use to host these user controls. What properties need to be changed.

On resizing the container, it should relocate the children so that the maximum children ae shown. Scrolling is okay as long as max are shown at any given time.

Is there a container that does this automatically? or should I manually create rows or panels or something and add n children to each - i.e., do it manually?

+2  A: 

I think what you need is a WrapPanel.

There's a Panels Overview on the MSDN with a lot more information and links to specific types of Panel including the WrapPanel:

WrapPanel positions child elements in sequential position from left to right, breaking content to the next line at the edge of the containing box. Subsequent ordering happens sequentially from top to bottom or right to left, depending on the value of the Orientation property.

ChrisF
Thanks :) God knows how long it would have taken me to find that on my own! :D
Senthil
+1  A: 

I think a good approach is to add the children horizontally until there is no more space to add another and then start another row.

This is exactly what a WrapPanel does.

Heinzi
+1 thanks. There I was, describing an existing control without knowing it :D
Senthil