In an attempt to waste less screen real-estate, I've used a StackPanel
to couple a Label
with its respective TextBox
twice, then wrapped those within a WrapPanel
. (In this example I am only referring to the Branch
and Phone
controls.)
When the screen is large enough, the two StackPanel
controls are side-by-side and fill the necessary width:
When the screen shrinks, the two StackPanel
controls are correctly wrapped, but leave blank space on the right:
Below is the xaml write-up to accomplish what I have thus far. Nevermind the validatingTextBoxStyle
as it only affects a red outline and error ToolTip
.
<WrapPanel
VerticalAlignment="Stretch"
Margin="0">
<StackPanel Orientation="Horizontal">
<Label
Content="Branch"
Margin="5,3"
Width="40"/>
<TextBox
x:Name="textBox"
Height="24"
Margin="5,0,5,5"
Style="{StaticResource validatingTextBoxStyle}"
Text="{Binding BranchNumber, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
MinWidth="150"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label
Content="Phone"
Margin="5,3"
Width="40"/>
<TextBox
x:Name="phone"
TabIndex="2"
Height="24"
Margin="5,0,5,5"
Style="{StaticResource validatingTextBoxStyle}"
Text="{Binding PhoneNumberToSearch, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
MinWidth="150"/>
</StackPanel>
</WrapPanel>
I've tried adding a Grid
layer with ColumnDefinitions
to resize the two StackPanel
controls, but that negates the wrapping functionality. I've tried setting their HorizontalAlignment
to Stretch
, but saw no change. I've also looked into this similar question on stretching a WrapPanel's child objects, but a UniformGrid
doesn't fit the situation.
Investigating further, I did note that the StackPanel
controls are not stretching as I thought they might, as noted below when a background color was added:
Is there a way to stretch these controls to fill the remaining width once they've been wrapped?