Some controls may support defining a custom panel in its
template. For instance, the ListBox supports setting up the panel you'd like
to use as the panel of choice for the ListBox. To define the listbox template,
use the following approach:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<c:WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
The WrapPanel element replaces the default panel for the
ListBox; this means each item uses the WrapPanel means for rendering list box
items. If the number of items overflows, the WrapPanel expands to encompass
the maximum height of the elements within the row.
Note that you cannot necessarily access the panel being used
to wrap the items in the ListBox. As was recommended by another poster on the
silverlight.net forums, the Loaded event for the ListBox passes the instance of
the panel via the sender property. This is the only way to access the
underlying panel, if you desire to. In most cases, you won't need to do so.