GroupBox Class

Updated: February 2009

Represents a control that creates a container that has a border and a header for user interface (UI) content.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public class GroupBox extends HeaderedContentControl
<GroupBox>
  Content
</GroupBox>

Content Model: GroupBox is a HeaderedContentControl. Its content property is Content and its header property is Header. For more information on the content model for GroupBox, see Controls Content Model Overview.

The following illustration is an example of a GroupBox that contains a TabControl and a Button that are enclosed in a StackPanel.

GroupBoxImage

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.

This example shows how to create a GroupBox that has a title and a visible border that encloses its content.

The following example defines a GroupBox control that is titled My Employee Info. The control encloses a TabControl and a Button in a StackPanel. The example sets the Header property to a Label.

  <GroupBox Width="300" Height="410">
    <GroupBox.Header>
      <Label>Employee Data</Label>
    </GroupBox.Header>
    <StackPanel>
    <TabControl Name="myTabControl" 
       TabStripPlacement="Top" 
		   Margin="0, 0, 0, 10" Height="350"
       >
      <TabItem Name="PersonalInfo">
        <TabItem.Header>_Personal Info</TabItem.Header>
        <StackPanel>
          <TextBlock>Employee</TextBlock>
          <TextBlock>Select your name</TextBlock>
          <ListBox Name="empName" SelectionChanged="updateSummary">
            <ListBoxItem IsSelected="true">Esther</ListBoxItem>
            <ListBoxItem>George</ListBoxItem>
            <ListBoxItem>Alan</ListBoxItem>
            <ListBoxItem>Eric</ListBoxItem>
          </ListBox>
         </StackPanel>
      </TabItem>
      <TabItem>
        <TabItem.Header>_Job Info</TabItem.Header>
          <StackPanel>
          <TextBlock>Select a job</TextBlock>
          <ListBox Name ="job" SelectionChanged="updateSummary">
            <ListBoxItem IsSelected="true">Programmer</ListBoxItem>
              <ListBoxItem>Tester</ListBoxItem>
              <ListBoxItem>Writer</ListBoxItem>
              <ListBoxItem>Manager</ListBoxItem>
            </ListBox>
          </StackPanel>
          </TabItem>
          <TabItem Name="Skill">
            <TabItem.Header>_Skill</TabItem.Header>
            <StackPanel>
              <TextBlock>
                  Select your strongest skill
              </TextBlock>
          <ListBox Name="skills" SelectionChanged="updateSummary">
              <ListBoxItem IsSelected="true">C#</ListBoxItem>
              <ListBoxItem>Visual Basic</ListBoxItem>
              <ListBoxItem>.NET</ListBoxItem>
              <ListBoxItem>JScript</ListBoxItem>
            </ListBox>
        </StackPanel>
        </TabItem>
        <TabItem Name="Summary" >
          <TabItem.Header>Su_mmary</TabItem.Header>
          <StackPanel>
          <TextBlock Name="emp"/>
          <TextBlock Name="ejob"/>
          <TextBlock Name="eskill"/>
        </StackPanel>
      </TabItem>
    </TabControl>
      <Button Content="Show Summary" Click="goToSummaryTab"/>
    </StackPanel>
  </GroupBox>

You must also define an event handler on a code-behind page in order to handle the Click event that occurs when a user clicks the Show Summary button.

For the complete sample, see GroupBox Sample.

More Code

How to: Define a GroupBox Template This example shows how to create a template for a GroupBox control.
How to: Create a Control That Has an Access Key and Text Wrapping This example shows how to create a control that has an access key and supports text wrapping. The example uses a Label control to illustrate these concepts.

System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Control
              System.Windows.Controls.ContentControl
                System.Windows.Controls.HeaderedContentControl
                  System.Windows.Controls.GroupBox

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Date

History

Reason

February 2009

Described how default styles change dependency properties.

Customer feedback.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft