我StackPanel在 WPF 中有一個包含Labels 和TextBoxes 的,它StackPanel的方向是Vertical. 我希望讓孩子們在 的剩余高度之間均勻分布StackPanel,或者每個 UI 元素之間可能有一些動態填充或其他東西,我不知道該怎么做。
這是它目前的樣子:
<StackPanel Margin="10 0" Grid.Row="1" Grid.RowSpan="3" Grid.Column="1">
<Label>Template Name:</Label>
<TextBox x:Name="templateNameTextBox"></TextBox>
<Label>Object Name:</Label>
<TextBox x:Name="objectNameTextBox"></TextBox>
<Label>Custom Name:</Label>
<TextBox x:Name="customNameTextBox"></TextBox>
</StackPanel>
最后一個下方只有一噸空白空間TextBox。我知道我可能不得不在某個時候將每個Label和對應TextBox的內容放在他們自己的面板中,以便將它們分組,但在我弄清楚間距之前我并沒有為此煩惱。如果可能的話,我只是不想為每一個都放置靜態值以使它們正確間隔。
解決了:
謝謝你,當你提到網格時,我并沒有考慮他們在自己的行中,這是有道理的,現在你提到它很清楚。統一的網格應該可以作業,因為它們都需要均勻分布。我還沒有使用uniformgrid,也不知道它們是用來做什么的,所以謝謝你把我帶到他們那里,我想這就是我會選擇的。
uj5u.com熱心網友回復:
為了平均分配空間,您可以使用Grid具有默認星號大小的 a(*對于每一行)。
在 Grid 中定義的列和行可以利用星型大小來按比例分配剩余空間。When Star is selected as the height or width of a row or column, that column or row receives a weighted proportion of the remaining available space.
它可能看起來像這樣(我將StackPanels 添加到組標簽和文本框)。
<Grid Margin="10 0" Grid.Row="1" Grid.RowSpan="3" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
VerticalAlignment="Center">
<Label>Template Name:</Label>
<TextBox x:Name="templateNameTextBox"></TextBox>
</StackPanel>
<StackPanel Grid.Row="1"
VerticalAlignment="Center">
<Label>Object Name:</Label>
<TextBox x:Name="objectNameTextBox"></TextBox>
</StackPanel>
<StackPanel Grid.Row="2"
VerticalAlignment="Center">
<Label>Custom Name:</Label>
<TextBox x:Name="customNameTextBox"></TextBox>
</StackPanel>
</Grid>
由于所有元素的分布應該相等,因此您也可以使用UniformGrid.
<UniformGrid Margin="10 0" Grid.Row="1" Grid.RowSpan="3" Grid.Column="1">
<StackPanel VerticalAlignment="Center">
<Label>Template Name:</Label>
<TextBox x:Name="templateNameTextBox"></TextBox>
</StackPanel>
<StackPanel VerticalAlignment="Center">
<Label>Object Name:</Label>
<TextBox x:Name="objectNameTextBox"></TextBox>
</StackPanel>
<StackPanel VerticalAlignment="Center">
<Label>Custom Name:</Label>
<TextBox x:Name="customNameTextBox"></TextBox>
</StackPanel>
</UniformGrid>-->
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424225.html
