Proper layout and positioning are a vital part of interactive, high-performance and user-friendly Windows applications. This series of articles explains the layout process in WPF. The series starts with an understanding of the WPF layout process. The next part of this series will cover the basics of layout and positioning such as size, margin, padding and alignment of elements. Later in this series, I will cover various panels and related parent controls available in WPF.
Table of Contents
IntroductionIn the previous article, WPF Layout: StackPanel, I discussed the StackPanel. This article focuses on the WrapPanel in details.WrapPanelWrapPanel is similar to StackPanel but it has an additional feature. If elements that are stacked horizontally or vertically don't fit in the row or column they are in, the remaining elements will wrap around in the same sequence.The WrapPanel element in XAML represents a WrapPanel. The following code snippet creates a WrapPanel and sets its height, width and background properties at design-time using XAML.
Listing 1
The output looks as in Figure 1 where all the child controls are wrapped horizontally.
Now if you change the orientation to vertical as in the following code, the output looks as in Figure 2.
Listing 2
SummaryIn this article, I discussed the WrapPanel in WPF. In the next article of this series, I will focus on Borders of WPF elements in details.