簡體   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