【问题标题】:Width of controls within horizontal stack panel水平堆栈面板中控件的宽度
【发布时间】:2012-08-02 17:53:07
【问题描述】:

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

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

【问题讨论】:

    标签: wpf


    【解决方案1】:

    您需要将ComboBoxTextBox 上的VerticalAlignment 设置为Center。默认设置为Stretch

    <TextBox VerticalAlignment="Center" ... />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多