主网格的每一行和每列中的网格大小都在减小

时间:2014-03-31 09:58:34

标签: c# wpf

我在xaml中声明了一个网格 -

 <Grid Grid.Row="1" x:Name="RejectedPartsGrid" >
 </Grid>

此网格中填充了代码隐藏的小网格 -

        for (int i = 0; i < 3; i++)
        {
            ColumnDefinition cd = new ColumnDefinition();
            RowDefinition rd = new RowDefinition();

            RejectedPartsGrid.ColumnDefinitions.Add(cd);

            RejectedPartsGrid.RowDefinitions.Add(rd);
        }

            for (int row = 0; row < 3; row++)
            {

                for (int column = 0; column < 3; column++)
                {

                    Grid gridImages = new Grid();

                    gridImages.Background = Brushes.Pink;

                    Grid.SetColumn(gridImages, column);

                    Grid.SetRow(gridImages, row);




                    gridImages.Margin = new Thickness(10);

                    ImageBrush myBrush = new ImageBrush();

                    Image image = new Image();
                    image.Stretch = Stretch.Fill;

                    if (imageCount < ListRejectedCarPartNames.Count)
                    {

                        carPartName = ListRejectedCarPartNames.ElementAt(imageCount);
                        conn.Open();
                        if (carPartName.Trim() != String.Empty)
                        {
                            using (SqlCeCommand com = new SqlCeCommand("SELECT CarImage FROM CarPartsImageMapping where CarPart = '" + carPartName + "'", conn))
                            {

                                SqlCeDataReader reader = com.ExecuteReader();

                                while (reader.Read())
                                {

                                    carImagePath = reader.GetString(0);

                                }

                            }
                            image.Source = new BitmapImage(new Uri( System.Environment.CurrentDirectory + "\\" + carImagePath, UriKind.Relative));
                            myBrush.ImageSource = image.Source;
                            gridImages.Background = myBrush;
                        }

                        conn.Close();
                    }

                    RejectedPartsGrid.Children.Add(gridImages);

                    imageCount++;

}

我正在使用kinect,当我在小网格负载中向左滑动图像时,但问题是当窗口加载时,主网格内的小网格的大小足够大,但是在图像滑动动作之后在小网格中加载网格的大小减少,在第二次刷卡时它减少了更多.. - 我希望gridImages网格一直是静态的,怎么做?

0 个答案:

没有答案