0

我有一个具有这种结构的窗口: 在此处输入图像描述

然后在构造函数窗口后面的代码中添加以下代码:

int numRow = 2;
  int numColumn = 3;

  for (int row = 0; row < numRow; row++)
  {
    var rd = new RowDefinition();
    rd.Height = new GridLength(1.0, GridUnitType.Star);
    grdMain.RowDefinitions.Add(rd);
  }

  for (int column = 0; column < numColumn; column++)
  {
    var cd = new ColumnDefinition();
    cd.Width = new GridLength(1.0, GridUnitType.Star);
    grdMain.ColumnDefinitions.Add(cd);
  }

  for (int row = 0; row < numRow; row++)
  {
    for (int column = 0; column < numColumn; column++)
    {
      //var borderImage = new Border();
      //borderImage.BorderThickness = new Thickness(1);
      //borderImage.BorderBrush = new SolidColorBrush(Colors.Red);

      var finalImage = new Image();
      BitmapImage logo = new BitmapImage();
      logo.BeginInit();
      logo.UriSource = new Uri("pack://application:,,,/EasyRun;component/Resources/Images/ITA.png");
      logo.EndInit();
      finalImage.Source = logo;

      //borderImage.Child = finalImage;

      Grid.SetRow(finalImage, row);
      Grid.SetColumn(finalImage, column);
      grdMain.Children.Add(finalImage);
    }

通过这样做,我希望窗口根据父窗口的大小调整行和列的大小。但是发生的情况是,虽然水平拉伸有效,但垂直拉伸无效。 在此处输入图像描述

在此处输入图像描述

所以简而言之,我想要的是根据其父窗口大小拉伸列/行的网格

4

1 回答 1

1

尝试使用停靠面板而不是堆栈面板

 <DockPanel Name="stpMain">
 <Button DockPanel.Dock="Bottom" Content="AAA" Width="100" Click="Button_Click"></Button>
 <Border BorderThickness="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0" BorderBrush="Red">
   <Grid Name="grdMain"></Grid>
 </Border>

于 2016-01-25T09:07:20.307 回答