繁体   English   中英

如何在C#WPF XAML中使用GroupBox来仅包装特定元素

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM