I have a StackPanel in WPF that contains Labels and TextBoxes, the StackPanel's orientation is Vertical. I'm looking to have the children spaced evenly amongst the remaining height of the StackPanel, or maybe some dynamic padding or something between each UI element and I'm not sure how to do this.
This is what it currently looks like:
<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>
There is just a ton of empty space below the last TextBox. I know I'll probably have to put each Label and corresponding TextBox in their own panel at some point so that they're grouped, but I haven't bothered with that until I figure out the spacing. I just don't want to have to put static values for each one to get them spaced properly, if possible.
Solved:
Thank you, I wasn’t thinking about them being in their own row when you mentioned a grid, that makes sense and is clear now that you mentioned it. The uniform grid should work as they all do need to be evenly spaced. I haven’t yet used a uniformgrid and didn’t know that’s what they were for, so thank you for leading me to them, I think that’s what I will opt for.
In order to distribute the space evenly, you could use a
Gridwith the default star-sizing (*for each row).It could look like this (I added
StackPanels to group labels and text boxes).Since the distribution should be equal for all elements, you could alternatively use a
UniformGrid.