Reputation:
I'm trying to put some elements inside of a GroupBox
in C# WPF XAML
code. I'm not sure how to implement it correctly.
Basically I want:
<Grid HorizontalAlignment="Center" Width="1000">
<GroupBox Header = "This stuff is in GroupBox ">
<Label> Label in GroupBox </Label>
<Label> Some other label in GroupBox </Label>
</GroupBox>
<Label> This is not in the groupbox so don't put me in it! <Label>
</Grid>
Upvotes: 1
Views: 575
Reputation: 37060
Instead of the outermost Grid
, use
<StackPanel Orientation="Vertical">
<GroupBox Header = "This stuff is in GroupBox ">
<Label> Label in GroupBox </Label>
<Label> Some other label in GroupBox </Label>
</GroupBox>
<Label> This is not in the groupbox so don't put me in it! <Label>
</StackPanel>
Either that or give the Grid
some RowDefinitions, and give Grid.Row
properties to the GroupBox
and the outer Label
. But the StackPanel
is quick, and perfect for your case.
Upvotes: 1
Reputation: 20451
Your GroupBox and Label are in the same grid so will lay on top of each other.
Try this:
<Grid HorizontalAlignment="Center" Width="1000">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<GroupBox Header = "This stuff is in GroupBox ">
<Label> Label in GroupBox </Label>
<Label> Some other label in GroupBox </Label>
</GroupBox>
<Label Grid.Row="1"> This is not in the groupbox so don't put me in it! <Label>
</Grid>
Upvotes: 2