我知道這看起來像一個簡單的問題,但我無法爲我的生活找到如何使網格有能力看穿它。我已經嘗試使背景透明,但是這不起作用。我在XAML中有一個文本框和一張圖片(我的程序中的所有其他部分,包括網格,都是以編程方式編寫的),但我不再看到文本框或圖像,我只看到網格。任何幫助?在網格中顯示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;
}
你能顯示將'grid_Main'添加到Windows Grid的代碼 –
@ sa_ddam213我剛添加它,它在「// Cre吃網格「 – Andrew
然後,你的問題是你正在用你的新網格替換當前的Windows內容(網格,圖像,文本框)。 –