21

A XAML StackPanel aligns controls side-by-side in a single direction. A WrapPanel is similar but like TextWrapping="Wrap" in a XAML TextBox the controls "wrap" to the next column or row when the respective height or width is reached.

enter image description here

Similar, but not the same, WrapGrid wraps content, but in a uniform grid. Though the VariableSizedWrapGrid allows for dissimilar items in the container. Neither of the WrapGrids can be used outside of an ItemsControl. So, they are disqualified.

When developers look in their native XAML Toolbox in Visual Studio there is no WrapPanel. WPF developers had a WrapPanel so they might be looking for this common tool to solve their scenario. So, I have to ask:

Does anyone know of a WrapPanel in XAML-WinRT? (what about one that is virtualized?)

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
  • +1 I have been looking for this very same thing. It is a pain to have to manually set the rows and columns of each item in a gridview. I *think* it can be done by overriding `ArrangeOveride`. I had a failed attempt at it once, and haven't looked at it again. ArrangeOverride at MSDN: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.frameworkelement.arrangeoverride.aspx – chue x May 31 '13 at 16:00

2 Answers2

9

There is one in WinRT XAML Toolkit here. It was ported from Silverlight Toolkit.

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • 2
    As long as we understand the answer is "no", Filip, I will mark this as the correct answer. There is no WrapPanel in WinRT. There are open source and third party WrapPanels, however. Mine is here: http://codepaste.net/8gr5go – Jerry Nixon Jun 07 '13 at 23:14
  • Tim also has one. I think from the same source as mine. – Filip Skakun Jun 08 '13 at 17:40
  • Yeah, mine is based on a version somewhere on CodeProject. I emailed the guy and asked if I could absorb it. For all I know his is based on the Toolkit, too. A lot of clipboard Inheritance on the web. – Jerry Nixon Jun 10 '13 at 15:17
  • Looks good and works, but I am confused about the license. On the project page it says it's released under the MIT License, but in the header of the WrapGrid code the Ms-PL license is mentioned, which seems to be an "infectious" Open Source license. So, can I use it in commercial, proprietary, closed-source software, or not? – Sebastian Negraszus Aug 08 '13 at 13:44
  • The `WrapPanel` from the WinRT XAML Toolkit is definitely better than the one from CodeProject that Jerry Nixon used. – HappyNomad Dec 17 '13 at 07:18
  • I am creating a Windows Phone 8.1 (WinRT) application. The template is a two GridView (2 grids per row) and the height of grid varies (one item might occupy one row and other might occupy two rows). I was able to achieve it using VariableSizedGridView and I did lazy loading as well. But I could find that there is no virtualization because of which the memory goes on increasing on scrolling down. Can you suggest me the how to achieve variable sized grid with virtualization like the pin.it app? http://bit.ly/1Y3X5Dl – meetme Mar 03 '16 at 07:16
  • Group your items source into pairs and use a regular ListView where each ListViewItem can display two items. – Filip Skakun Mar 03 '16 at 14:53
0

I had a same requirement and after googled it for a while, I've decided to use custom control for this. Please find following link for implementation:

http://www.codeproject.com/Articles/463860/WinRT-Custom-WrapPanel

Hope this will help you.

Vishal
  • 171
  • 7
  • 1
    Vishal. I don't see the advantage of your control to WrapGrid, since, as far as I understand, it assumes fixed element size (width for Horizontal orientation). The whole idea is to allow variable element width, so that you dynamically check if the new element fits in and place it on next line, if it doesn't. – cyanide Dec 17 '15 at 22:22