WPF中的QT间隔物等效物

时间:2013-09-09 15:18:33

标签: xaml stackpanel

我有一个带有一些垂直对齐控件的StackPanel(此图中右侧的stackpanel: enter image description here

最后一个控件应始终放在边框控件内部窗口的底部(图片上的“确定”按钮)。在QT中,我插入一个间隔控件来按下按钮。我如何在WPF中做到这一点?谢谢。这是xaml:

<Window x:Class="Test.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       Title="MainWindow" Height="350" Width="525">
    <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="354*" />
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <Border Margin="5" Background="Gray" CornerRadius="6" BorderBrush="Gray">
      <Viewport3D Grid.Column="0" Name="viewport" ClipToBounds="True">
      </Viewport3D>
    </Border>

    <Border Grid.Column="1" CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="1" Margin="5" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Stretch" >
      <StackPanel>
        <StackPanel Orientation="Horizontal">
          <Label Content="Dimension" Name="label1" VerticalAlignment="Center" />
          <ComboBox Text="3D" HorizontalAlignment="Right" Name="dimensioncb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
            <ComboBoxItem>2D</ComboBoxItem>
            <ComboBoxItem>3D</ComboBoxItem>
          </ComboBox>
        </StackPanel>
        <Separator/>
        <DockPanel>
          <Label Content="Iteration" Name="label2" VerticalAlignment="Center" />
          <ComboBox Text="3" HorizontalAlignment="Right" Name="iterationcb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
            <ComboBoxItem>1</ComboBoxItem>
            <ComboBoxItem>2</ComboBoxItem>
            <ComboBoxItem>3</ComboBoxItem>
            <ComboBoxItem>4</ComboBoxItem>
            <ComboBoxItem>5</ComboBoxItem>
            <ComboBoxItem>6</ComboBoxItem>
            <ComboBoxItem>7</ComboBoxItem>
            <ComboBoxItem>8</ComboBoxItem>
          </ComboBox>
        </DockPanel>
        <Button Content="OK" VerticalAlignment="Bottom"/>
      </StackPanel>
    </Border>

  </Grid>
</Window>

1 个答案:

答案 0 :(得分:2)

有很多方法可以在WPF中完成此任务。如下所示是:

<Border Grid.Column="1" CornerRadius="6" BorderBrush="Gray" Background="LightGray" BorderThickness="1" Margin="5" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Stretch" >
  <!--Add a grid control to separate your stackpanel and button-->
  <Grid>
    <Grid.RowDefinitions>
       <RowDefinition Height="*"/>
       <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
  <StackPanel Grid.Row="0">
    <StackPanel Orientation="Horizontal">
      <Label Content="Dimension" Name="label1" VerticalAlignment="Center" />
      <ComboBox Text="3D" HorizontalAlignment="Right" Name="dimensioncb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
        <ComboBoxItem>2D</ComboBoxItem>
        <ComboBoxItem>3D</ComboBoxItem>
      </ComboBox>
    </StackPanel>
    <Separator/>
    <DockPanel>
      <Label Content="Iteration" Name="label2" VerticalAlignment="Center" />
      <ComboBox Text="3" HorizontalAlignment="Right" Name="iterationcb" VerticalAlignment="Center" IsReadOnly="True" IsEditable="True">
        <ComboBoxItem>1</ComboBoxItem>
        <ComboBoxItem>2</ComboBoxItem>
        <ComboBoxItem>3</ComboBoxItem>
        <ComboBoxItem>4</ComboBoxItem>
        <ComboBoxItem>5</ComboBoxItem>
        <ComboBoxItem>6</ComboBoxItem>
        <ComboBoxItem>7</ComboBoxItem>
        <ComboBoxItem>8</ComboBoxItem>
      </ComboBox>
    </DockPanel>
  </StackPanel>
    <Button Grid.Row="1" Content="OK" VerticalAlignment="Bottom"/>
  </Grid>
</Border>

上面的XAML用于替换XAML中的右侧Border将产生以下结果,并在重新调整窗口大小时将按钮保持在底部。

enter image description here