Originally I hadn’t planned to mention the WrapPanel, because in my view it’s not an overly useful control. I have a hard time imagining when you might want to use it, but in playing with it I actually came up with one scenario, perhaps someone will be able to offer some more.
Using the control is easy, simply put <WrapPanel> and it’s ending tag in a Window or Page, then put the controls inside you want. Then as you resize the window, the controls inside will automatically shift around to make use of the available space.
For today’s example, create the WrapPanel tags, and inside put 8 buttons.
I then stretched out the window so you can see all 8 horizontally:
Now if I simply resize the window a bit, you’ll see the controls rearrange themselves automatically:
And of course I can make them all go vertical if I want:
The one way I can think this might be useful is if you were to create a floating toolbar. In that form it might be handy to have the toolbar buttons moving around. Odds are there are better ways to create a floating toolbar, but if you needed something simple this might be an answer for you.
Other than that one example I can’t think of a lot of uses for it, but if you know some by all means post a comment. Meanwhile at least you’ll be familiar with the WrapPanel container.
2 thoughts on “Wrapping up containers with the WPF WrapPanel”
You can also use this panel when showing photo’s (or thumbnails) in a gallery for example.
I am using it for listing character portraits in an RPG manager. As more characters are loaded, they just keep wrapping around. Very useful when programmatically adding items of a known and fixed size.