从网格中删除图像

时间:2013-05-29 19:08:41

标签: c# image grid

我正在尝试使用每秒钟下降的计数器从grid_main中删除grid_main中的图像,但是图像仍然停留在那里而没有删除功能。如果在3秒内点击痣,那么它将起作用,但是如果它被卡在那里之后被点击了。谢谢!

代码:

MoleLifeCounter = 3;

// Create Grid \\
            Content_Grid.Children.Add(grid_Main);
            grid_Main.Height = MainWindowHeight;
            grid_Main.Width = MainWindowWidth;
            grid_Main.Background = Brushes.Transparent;

            // Grid Properties \\
            for (int i = 0; i < NumberOfColumns; i++)
            {
                ColumnDefinition newColumn = new ColumnDefinition();
                newColumn.Width = new GridLength(ColumnSize, GridUnitType.Pixel);
                grid_Main.ColumnDefinitions.Add(newColumn);
            }

            for (int i = 0; i < NumberofRows; i++)
            {
                RowDefinition Row = new RowDefinition();
                Row.Height = new GridLength(RowSize, GridUnitType.Pixel);
                grid_Main.RowDefinitions.Add(Row);
            }

            // Fill Grid \\
            int RowCount = 0;
            int ColumnCount = 0;
            for (int i = 0; i <= NumofImages; i++)
            {
                Image newImage = HoleImage();
                if (RowCount < NumberofRows)
                {
                    if (ColumnCount < NumberOfColumns)
                    {
                        Console.WriteLine("ColumnCount: " + ColumnCount.ToString());
                        Grid.SetRow(newImage, RowCount);
                        Grid.SetColumn(newImage, ColumnCount);
                        grid_Main.Children.Add(newImage);
                        ColumnCount++;
                    }

                    else
                    {
                        RowCount++;
                        ColumnCount = 0;
                        Grid.SetRow(newImage, RowCount);
                        Grid.SetColumn(newImage, ColumnCount);
                        grid_Main.Children.Add(newImage);
                        ColumnCount++;
                        Console.WriteLine("RowCount: " + RowCount.ToString());
                    }
                }

                else
                {
                    break;
                }

                ChangeImage();
            }
        }

    private void deleteMole()
    {
        MoleLifeCounter = MoleLifeCounter--;

        if (MoleLifeCounter == 0)
        {
            grid_Main.Children.Remove(molePopup);
            MoleLifeCounter = 3;
        }
    }

0 个答案:

没有答案