Figure 4-2. The StackPanel in action
CHAPTER 4 n LAYOUT 81
USING THE STACKPANEL IN VISUAL STUDIO
It??™s relatively easy to create this example using the designer in Visual Studio. Begin by deleting the root Grid
element (if it??™s there). Then, drag a StackPanel into the window. Next, drag the other elements (the label and
four buttons) into the window, in the top-to-bottom order you want.
If you want to rearrange the elements in the StackPanel, you can??™t simply drag and drop them. Instead,
right-click the element you want to move, and choose an option from the Order submenu. The ordering
options correspond to the order of the elements in the markup, with the first element occupying the back
position and the last element occupying the front position. Thus, you can move an element down to the bottom
of the StackPanel (using Bring to Front), up to the top (using Send to Back), or one position down or up
(using Bring Forward and Send Backward).
You need to consider a few quirks when you create a user interface with Visual Studio. When you drag
elements from the Toolbox to a window, Visual Studio adds certain details to your markup. Visual Studio automatically
assigns a name to every new control (which is harmless but unnecessary). It also adds hard-coded
Width and Height values, which is much more limiting.
Pages:
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204