Examining Various Silverlight Containers
page 3 of 8
by Brian Mains
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 35960/ 81


Enter the StackPanel control, one of the several panels this article will discuss today.  The StackPanel element is responsible for stacking elements vertically on the screen.  However, by adjusting the orientation property, the StackPanel element can render horizontally too.  The prime function of this element is to stack its children one on top of the other.  The StackPanel doesn't wrap to the next line; this means that the content has to fit, or else clipping of content may occur.  This scenario works will when a Min/Max width are specified for its children, but even this may not prevent clipping from occuring, depending on the size of the content and its restrictions.

The StackPanel works by adding one or more children to it, as any other panel works (even in the ASP.NET work, with the Panel server control).  All of the inner children get positioned accordingly.  To solve the situation desribed above, where the Grid cannot display multiple controls in the same cell, the StackPanel can be used to save the design as shown in Listing 4.

Listing 4: Using the StackPanel

<Grid ..>
      <TextBlock Grid.Row="5" Grid.Column="0" Text="Contact Numbers" />
      <StackPanel Grid.Row="5" Grid.Column="1">
            <TextBox Name="PN1" />
            <TextBox Name="PN2" />
            <TextBox Name="PN3" />

Each of the three phone number textboxes renders vertically within row 5, column 1, because of the StackPanel.  Markup becomes easier too because the StackPanel stores the row/column, not each textbox.

The StackPanel doesn't use attached properties, so implementation is very straightforward.  Because it's very easy to use, this makes for a good candidate to replace the Grid as the child of the UserControl.  In a lot of situations, I often delete the default Grid child and use a StackPanel instead.  The vertical nature of a page often makes this a prime parent choice.  However, this control wouldn't be as useful in developing forms without the next control.

View Entire Article

User Comments

Title: Microsoft.Windows.Controls   
Name: Evgen
Date: 2010-08-26 4:42:38 AM
May be
instead of
Title: Silverlight   
Name: Prabhakar
Date: 2009-07-15 7:51:36 AM
This is article very useful. I have query "Can we add a xmal file inside any panel/etc.." I want to display all my xaml files/controls to display in one page. Please advice me if it is possible.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-06-18 5:19:24 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search