2

我有一个程序,我正在向它添加一个按钮,我通过说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>
4

1 回答 1

0

我找到了答案,我所做的只是在 XAML 中添加一个网格,并摆脱了后面代码中的网格。

于 2013-06-04T17:53:48.823 回答