The GroupBox control is a HeaderedContentControl that provides a titled container for user interface (UI) content. This topic introduces the GroupBox control and provides a beginning example of its use.
This topic contains the following sections.
What Is a GroupBox?
The default GroupBox style provides a box with a visible border and a title. A GroupBox control can contain only one child element; however, that child element can be any UIElement, which includes layout elements like StackPanel and Canvas. These layout elements can contain many items, and enable you to add complex content to a GroupBox.
Creating a GroupBox
<GroupBox Margin="0,20,0,0" Width="150" Height="200"> <GroupBox.Header> My Favorite City </GroupBox.Header> <StackPanel> <TextBlock Margin="0,10,0,0">Type your name:</TextBlock> <TextBox Width="100"/> <TextBlock Margin="0,5,0,0">Select your favorite city:</TextBlock> <TextBlock>Select your name</TextBlock> <ListBox Name="empName"> <ListBoxItem IsSelected="true">Paris</ListBoxItem> <ListBoxItem>Beijing</ListBoxItem> <ListBoxItem>Buenos Aires</ListBoxItem> <ListBoxItem>Chicago</ListBoxItem> </ListBox> <Button Margin="0,20,0,0" Width="50" Click="SubmitCode">Submit</Button> </StackPanel> </GroupBox>
The following illustration shows the GroupBox that is created by the previous example.
GroupBox created by this example
GroupBox Behavior and Appearance
The GroupBox control inherits all its properties and methods except for its constructor. A key inherited property for GroupBox is the Header property, which sets the title of the GroupBox. The default style for a GroupBox includes a Header, a Content area, and a Border. The GroupBox Style hides part of the Border to make room for the Header to appear.