我有一个要向其中添加按钮的程序,我说的是Content_Grid.Children.Add(grid_Main),但我尝试单击它时却无法单击。
背后的代码:
// Create Grid \\
Content_Grid.Children.Add(grid_Main);
grid_Main.Height = MainWindowHeight;
grid_Main.Width = MainWindowWidth;
grid_Main.Background = Brushes.Transparent;
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">
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Can You Catch the Mole?" VerticalAlignment="Bottom" Height="85" Width="460" FontFamily="SimHei" FontSize="36" Margin="10,0,0,-27"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="475,0,0,16" VerticalAlignment="Bottom" Width="90" Height="42"/>
</Grid>
</Window>
最佳答案
我找到了答案,我所要做的就是在XAML中添加一个网格,并摆脱了后面代码中的网格。