GroupBox Overview

.NET Framework 3.0

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.

The following illustration shows a GroupBox that contains a TabControl and a Button that are enclosed in a StackPanel.

Simple GroupBox

GroupBoxImage

Creating a GroupBox

The following Extensible Application Markup Language (XAML) example creates a simple GroupBox that contains a TextBox control, a ListBox control, and a Button inside a StackPanel.

<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 screen shot

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.

A GroupBox does not accept focus and is excluded from Tab key navigation. A GroupBox sets both Focusable and IsTabStop to false.

See Also

Community Additions

ADD
Show: