按钮在XAML中不可单击

时间:2013-06-04 17:42:14

标签: c# xaml grid

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

1 个答案:

答案 0 :(得分:0)

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