Using a WrapPanel in Conjunction with a ListBox

WrapPanel is useful to present a list of items using XAML. However, using a WrapPanel to present a bound list of values located in a viewmodel can be best achieved by supplanting the ItemsPanelTemplate of a ListBox with a WrapPanel.

This technique is demonstrated in the downloadable sample code. The WrapPanelViewModel class contains a list of strings, representing the numbers 1 to 5, which we use as the source collection for a ListBox control. The list of strings is generated using the LINQ Range and Select methods. See the following excerpt:

readonly IEnumerable<string> items    = Enumerable.Range(1, 5).Select(x => x.ToString());public IEnumerable<string> Items{     ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.