Windows应用商店应用按钮单击事件不触发网格模板

时间:2013-09-28 05:54:47

标签: button windows-store-apps winrt-xaml

我使用VS2012的默认网格模板创建了一个项目,并在右上角添加了一个按钮,它不可点击,如果我删除了GridView,那么它是可点击的。对我来说很奇怪,有人可能会指出为什么会这样吗

<Grid Style="{StaticResource LayoutRootStyle}">
    <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Back button and page title -->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
        <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
        <Button 
            x:Name="SettingsButton"
            Grid.Column="2"
            HorizontalAlignment="Right" 
            VerticalAlignment="Center" 
            Margin="0,0,120,0" 
            AutomationProperties.Name="Settings" 
            Content="Settings"
            Click="SettingsButton_Click"
              />
    </Grid>

    <GridView .... />
</Grid>

1 个答案:

答案 0 :(得分:0)

您的GridView正在按钮网格上绘制。将按钮网格声明移动到GridView下面。

<Grid Style="{StaticResource LayoutRootStyle}">
    <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Move the GridView Here -->
    <GridView .... />

    <!-- Back button and page title -->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
        <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
        <Button 
            x:Name="SettingsButton"
            Grid.Column="2"
            HorizontalAlignment="Right" 
            VerticalAlignment="Center" 
            Margin="0,0,120,0" 
            AutomationProperties.Name="Settings" 
            Content="Settings"
            Click="SettingsButton_Click"
              />
    </Grid>
</Grid>