[英]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.