The GroupBox is a familiar control for organizing numerous controls. You might use it to surround a group of CheckBoxes or radio buttons. The GroupBox is a content control, and as a content control, it can only have one child. You need to set a GroupBox’s content to an intermediate control that can contain multiple children. For example, you might use a StackPanel.
The Header property of the GroupBox can be set to an arbitrary object. If that object derives from UIElement, it is rendered as expected. For example, the header could be a fully-functional Button.
1 | < Window x:Class = "GroupBoxSimple.MainWindow" |
6 | xmlns:local = "clr-namespace:GroupBoxSimple" |
8 | WindowStartupLocation = "CenterScreen" |
9 | Title = "GroupBoxSimple" Height = "200" Width = "300" > |
11 | < GroupBox Margin = "10" > |
13 | < Button Click = "Button_Click" >To Do</ Button > |
16 | < CheckBox >Shovel the Snow</ CheckBox > |
17 | < CheckBox >Cut the grass</ CheckBox > |
18 | < CheckBox >Take out the garbage</ CheckBox > |
Here is some code behind.
3 | namespace GroupBoxSimple |
5 | public partial class MainWindow : Window |
11 | private void Button_Click( object sender, RoutedEventArgs e) |
13 | MessageBox.Show( "Some work to do." , "GroupBoxSimple" , |
14 | MessageBoxButton.OKCancel, MessageBoxImage.Warning); |