
Nesting Panels within Panels
When you are building a Window, you will typically find that the Content property is a panel that contains
additional panels. This allows you to carve out chunks of screen space, where each chunk behaves uniquely.
You may wish to have part of your UI resize content when maximized, where another part of your UI should
remain fixed.
Consider the following DockPanel. The DockPanel has set the LastChildFill property to true, which is the
default. In this way, the TextBlock will take up the remainder of the UI, regardless of the window’s size. The
DockPanel defines a <Menu> (docked to the top), <StatusBar> (docked to the bottom), and a
<StackPanel> docked to the left. The <StackPanel> contains a set of UI elements.
<!-- This panel establishes the content for the window. -->
<DockPanel LastChildFill="True">
<!-- Put a Menu and toolbar at the top. -->
<Menu DockPanel.Dock = "Top" HorizontalAlignment = "Left"
Background = "White">
<MenuItem Header = "_File">
<Separator/>
<MenuItem Header = "_Exit" />
</MenuItem>
</Menu>
<!-- Put a StatusBar at the bottom. -->
<StatusBar Name = "statBar"
DockPanel.Dock = "Bottom"
VerticalAlignment = "Bottom"
Background = "Beige" >
<StatusBarItem>
<TextBlock>Ready</TextBlock>
</StatusBarItem>
</StatusBar>
<!-- Put a StackPanel on the left. -->
<StackPanel Background = "LightSteelBlue" Orientation = "Vertical"
DockPanel.Dock = "Left">
<Label Name = "lblInstruction"
FontSize = "15">Enter Car Information</Label>
<Label Name = "lblMake">Make</Label>
<TextBox Name = "txtMake"/>
<Label Name = "lblColor">Color</Label>
<TextBox Name = "txtColor"/>
<Label Name = "lblPetName">Pet Name</Label>
<TextBox Name = "txtPetName"/>
<Button Name = "btnOK">OK</Button>
</StackPanel>
<!-- The final area will be a block of text wrapped in a border. -->
<Border BorderThickness = "3" BorderBrush = "DarkRed">
<TextBlock Background = "LemonChiffon" FontSize = "20">
Desktop markup? I like it!</TextBlock>
</Border>
</DockPanel>
Nesting Panels
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services