concept panel in category silverlight

appears as: pels, pel, panel, pels, The pel, Pel
Silverlight 4 in Action: Silverlight 4, MVVM, and WCF RIA Services

This is an excerpt from Manning's book Silverlight 4 in Action: Silverlight 4, MVVM, and WCF RIA Services.

The UserControl and Button are both content controls, a concept we’ll discuss in greater detail in chapter 10. For now, it’s important to understand that a content control may only have one direct child element, typically a panel that holds other elements. The x:Name and x:Class properties are part of the namespace specified by the xmlns:x statement. More on that in a moment... The Grid and StackPanel are both Panels, which is a type that has a Children collection to allow multiple contained elements. We’ll discuss panels in chapter 7.

Custom panels enable you to create your own specialized layout algorithms. For example, you may want a panel that lays out its children using concentric circles rather than a box model. Implementing custom panels also has a nice educational benefit: they help you visualize and understand the layout process. Once you’ve created a few panels of your own, you’ll find you better understand how the built-in ones work, and can better debug issues.

Panel is the base type for all layout panels in Silverlight, including the Canvas, Grid, and StackPanel. The class itself derives directly from FrameworkElement, so it’s a pretty low-level class, lacking the extras you’d find in something like Control. What it does include is important to Panels: the Children property.

The Children property is a UIElementCollection—it’s a specialized collection of child elements placed inside this panel. This is the key property that makes a Panel a Panel.

In addition to the Children property, the Panel class provides a Background brush property and a boolean IsItemsHost, which is used in concert with the ItemsControl class. Deriving from Panel allows you to substitute your panel for the StackPanel in a ListBox, for example.