GroupBox in WPF can only contain one element?

C#WpfGroupbox

C# Problem Overview


It seem that GroupBox can only contain one element, if I place more than one it's won't go inside(or get deleted in blend).

Is this by design or am I doing something wrong?

C# Solutions


Solution 1 - C#

That sounds right to me. You'd need to put a Grid or Panel (StackPanel, WrapPanel, etc) as a child to define the layout.

Solution 2 - C#

Yes, in WPF the GroupBox will contain maximum of 1 element. You can include Grid as its child and in grid specify your desired components. For example 1 placed two buttons in GroupBox using Grid.

Document Outline is shown below:

Document Outline

Code is as follow:

<GroupBox
            Header="Read Sensor"
            HorizontalAlignment="Left"
            Margin="485,4,0,0"
            VerticalAlignment="Top"
            Height="188"
            Width="238">
            <Grid
                HorizontalAlignment="Left"
                Height="169"
                Margin="0,0,-13,-3"
                VerticalAlignment="Top"
                Width="229">
                <Button
                    x:Name="btnReadSensor1"
                    Content="Read Sensor 1"
                    HorizontalAlignment="Left"
                    Margin="10,91,0,0"
                    VerticalAlignment="Top"
                    Width="207"
                    Click="btnReadSensor1_Click" />
                <Button
                    x:Name="btnReadSensor2"
                    Content="Read Sensor 2"
                    HorizontalAlignment="Left"
                    Margin="10,64,0,0"
                    VerticalAlignment="Top"
                    Width="207"
                    Click="btnReadSensor2_Click" />
            </Grid>
</GroupBox>

Solution 3 - C#

Well the real answer is because groupbox inherits from HeaderedContentControl

Take a look here MSDN

Solution 4 - C#

You must drag the items: textbox INTO the groupbox and must only have a single groupbox. Cannot drag more than a single groupbox per linear coordinate for it to work. Can have multiple groupboxes on a page, but not more than a single column wide or you will be limited with only having a single item being added to the groupbox.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAthiwat ChunlakhanView Question on Stackoverflow
Solution 1 - C#Luke QuinaneView Answer on Stackoverflow
Solution 2 - C#Hassan RahmanView Answer on Stackoverflow
Solution 3 - C#Aharon MuallemView Answer on Stackoverflow
Solution 4 - C#mikeView Answer on Stackoverflow