0

我知道这似乎是一个简单的问题,但我终其一生都无法找到如何使网格具有透视它的能力。我已经尝试过使背景透明,但这不起作用。我在 XAML 中有一个文本框和一张图片(我的程序中的所有其他内容,包括网格,都是以编程方式制作的),但我不再看到文本框或图像,我只看到网格。有什么帮助吗?

XAML:

<Window x:Name="MainWin" x:Class="WhackaMoleReal.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="421.378" Width="624.929">
    <Grid>
        <Image Margin="353,156,-131,-58" Source="mole2.png" Stretch="Fill"/>
        <TextBlock HorizontalAlignment="Left" Margin="20,10,0,0" TextWrapping="Wrap" Text="Can You Catch the Mole?" VerticalAlignment="Top" Height="79" Width="497" FontFamily="SimHei" FontSize="40"/>
    </Grid>
</Window>

C#:

        Grid grid_Main = new Grid();

// Create Grid \\
            MainWin.Content = grid_Main;
            grid_Main.Height = MainWindowHeight;
            grid_Main.Width = MainWindowWidth;
            grid_Main.Background = Brushes.Transparent;


                // 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;
                    }
4

1 回答 1

1

问题是您正在用新的网格(grid_Main)替换当前的窗口内容(网格、图像、文本框)。

看起来您只想将新网格 (grid_Main) 添加到现有的窗口网格

xml:

<Window x:Name="MainWin" x:Class="WhackaMoleReal.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="421.378" Width="624.929">
    <Grid x:Name="Content_Grid">
        <Image Margin="353,156,-131,-58" Source="mole2.png" Stretch="Fill"/>
        <TextBlock HorizontalAlignment="Left" Margin="20,10,0,0" TextWrapping="Wrap" Text="Can You Catch the Mole?" VerticalAlignment="Top" Height="79" Width="497" FontFamily="SimHei" FontSize="40"/>
    </Grid>
</Window>

C#:

Grid grid_Main = new Grid();

// Create Grid \\
Content_Grid.Children.Add(grid_Main);
于 2013-05-28T02:00:47.290 回答