[英]How to use GroupBox in C# WPF XAML to wrap only around specific elements
I'm trying to put some elements inside of a GroupBox
in C# WPF XAML
code. 我试图在C# WPF XAML
代码中将一些元素放在GroupBox
中。 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>
Your GroupBox and Label are in the same grid so will lay on top of each other. 您的GroupBox和Label位于同一网格中,因此将彼此叠加。
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>
Instead of the outermost Grid
, use 而不是最外面的Grid
,使用
<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
. 或者给Grid
一些RowDefinitions,并给GroupBox
和外部Label
赋予Grid.Row
属性。 But the StackPanel
is quick, and perfect for your case. 但StackPanel
很快,非常适合您的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.