Reputation: 545
I know it may seem like a simple question, but I can't for the life of me find how to make a grid have the ability to see through it. I have already tried making the background transparent, but that does not work. I have a textbox and a picture in XAML, (everything else in my program, including the grid, are made programatically), but I no longer see the textbox or the image, i just see the grid. Any Help?
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;
}
Upvotes: 0
Views: 198
Reputation: 43596
The problem is you are replacing the the current windows content (Grid,Image,TextBox) with your new grid(grid_Main).
It looks like you just want to add the new Grid (grid_Main) to the existing Window Grid
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 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);
Upvotes: 1