水平堆栈面板内控件的宽度

时间:2012-08-02 17:53:07

标签: wpf

在我的WPF应用程序中,我有一个水平StackPanel,我试图用作工具栏。在这个面板中,我有按钮,组合框和文本框。由于按钮是最高的,StackPanel占据了它们的高度。组合框和文本框也一样。但我希望他们保持原样,否则他们看起来很难看。如何防止它们扩展并填充所有可用空间?我试图将它们的高度设置为自动或显式大小,但这没有帮助。我也尝试用Grid替换StackPanel,但这也没有帮助。我究竟做错了什么?

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

1 个答案:

答案 0 :(得分:1)

您需要将VerticalAlignmentComboBox上的TextBox设置为Center之类的内容。默认情况下,它设置为Stretch

<TextBox VerticalAlignment="Center" ... />
相关问题