In my WPF application, I have a horizontal StackPanel that I am trying to use as a toolbar. Within this panel, I have buttons, comboboxes and textboxes. As the buttons are the tallest, the StackPanel takes their height. And the same do the comboboxes and textboxes. But I want them to stay as they are, otherwise they look ugly. How can I prevent them to expand and fill all available space? I tried to set their height to Auto or to an explicit size, but that didn’t help. I also tried to replace the StackPanel with a Grid, but this didn’t help either. What am I doing wrong?
<StackPanel Orientation="Horizontal" Margin="3, 10">
<ComboBox x:Name="Agencies" DisplayMemberPath="Name" SelectedValuePath="Value"
SelectedItem="{Binding SelectedAgency}"
Height="50" MinWidth="100" Margin="3,0"/>
<Button x:Name="UploadFile"
MinWidth="70"
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
attachProperties:ButtonIcon.Icon="Resources/Images/add.png"
Content="Upload File" IsEnabled="{Binding EnrollmentFiles.Any}"
Style="{StaticResource ImageButtonStyle}" />
<Button x:Name="EnrollmentDelete"
MinWidth="70"
Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
attachProperties:ButtonIcon.Icon="Resources/Images/Remove.png"
Content="Delete Enrollment" IsEnabled="{Binding EnrollmentFiles.Any}"
Style="{StaticResource ImageButtonStyle}" />
<TextBox x:Name="WorkSheetName" />
</StackPanel>
You need to set the
VerticalAlignmenton yourComboBoxandTextBoxto something likeCenter. By default it’s set toStretch