Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does WPF have a "static box" control?

Please see this image for what I'm referring to as a static box:

enter image description here

I'm not sure if that is it's proper name.

The box should be able to hold an arbitrary child control (panel etc.) inside.

like image 672
HighCommander4 Avatar asked Jan 19 '23 13:01

HighCommander4


1 Answers

In WPF, it is called a GroupBox

See the MSDN documentation for the control:

http://msdn.microsoft.com/en-us/library/system.windows.controls.groupbox.aspx

How to use it

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <GroupBox Header="Test 1">
        <StackPanel Margin="6">
            <RadioButton x:Name="option1RadioButton" Content="Option 1" />
            <RadioButton x:Name="option2RadioButton" Content="Option 2" />
            <RadioButton x:Name="option3RadioButton" Content="Option 3" />
        </StackPanel>
    </GroupBox>
</Window>

Cool features

The WPF GroupBox is a bit more powerful than your standard Win32 group box. Instead of just being able to set text in the header, you can set any sort of content you want, such as images, or other controls:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <GroupBox>
        <GroupBox.Header>
            <StackPanel Orientation="Horizontal">
                <Button Content="Test 1" />
                <Label Content="Test 2" />
                <Button Content="Test 3" />
            </StackPanel>
        </GroupBox.Header>
        <StackPanel Margin="6">
            <RadioButton x:Name="option1RadioButton" Content="Option 1" />
            <RadioButton x:Name="option2RadioButton" Content="Option 2" />
            <RadioButton x:Name="option3RadioButton" Content="Option 3" />
        </StackPanel>
    </GroupBox>
</Window>

group box with custom header content

like image 163
Merlyn Morgan-Graham Avatar answered Jan 29 '23 01:01

Merlyn Morgan-Graham