[英]How to use GroupBox in C# WPF XAML to wrap only around specific elements
我试图在C# WPF XAML
代码中将一些元素放在GroupBox
中。 我不确定如何正确实现它。
基本上我想要:
<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>
您的GroupBox和Label位于同一网格中,因此将彼此叠加。
尝试这个:
<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>
而不是最外面的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>
或者给Grid
一些RowDefinitions,并给GroupBox
和外部Label
赋予Grid.Row
属性。 但StackPanel
很快,非常适合您的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.