Windows 8 Windows应用商店应用:网格视图组标题按钮命令未触发?
我有一个具有以下组样式标题模板的网格视图:Windows 8 Windows应用商店应用:网格视图组标题按钮命令未触发?,windows-8,windows-store-apps,winrt-xaml,Windows 8,Windows Store Apps,Winrt Xaml,我有一个具有以下组样式标题模板的网格视图: <GroupStyle.HeaderTemplate> <DataTemplate> <Grid Margin="1,0,0,6"> <Button AutomationPr
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Command="{Binding GroupCommand}"
Style="{StaticResource TextPrimaryButtonStyle}"
>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
问题是,当我单击按钮时,GroupCommand不会执行
这里可能有什么问题?您应该尝试以下方法:
private void Button_Tapped_1(object sender, TappedRoutedEventArgs e)
{
SampleDataItem item = new SampleDataItem("test", "test!", "subtitle", "", "", "", null);
SampleDataSource.AddItemToFirstGroup(item);
}
private void Button_Tapped_2(object sender, TappedRoutedEventArgs e)
{
SampleDataGroup group = new SampleDataGroup("test", "testGroup", "subtitle", "", "");
group.Items.Add(new SampleDataItem("test", "test!", "subtitle", "", "", "", null));
SampleDataSource.AddGroup(group);
}
你应该这样做:
private void Button_Tapped_1(object sender, TappedRoutedEventArgs e)
{
SampleDataItem item = new SampleDataItem("test", "test!", "subtitle", "", "", "", null);
SampleDataSource.AddItemToFirstGroup(item);
}
private void Button_Tapped_2(object sender, TappedRoutedEventArgs e)
{
SampleDataGroup group = new SampleDataGroup("test", "testGroup", "subtitle", "", "");
group.Items.Add(new SampleDataItem("test", "test!", "subtitle", "", "", "", null));
SampleDataSource.AddGroup(group);
}
我从这里得到的
我想将我的按钮绑定到ViewModel中的ICommand,所以我这样做:
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Command="{Binding ElementName=myParentGridView, Path=DataContext.GroupCommand}"
Style="{StaticResource TextPrimaryButtonStyle}"
>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
我从这里得到的
我想将我的按钮绑定到ViewModel中的ICommand,所以我这样做:
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Command="{Binding ElementName=myParentGridView, Path=DataContext.GroupCommand}"
Style="{StaticResource TextPrimaryButtonStyle}"
>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
尝试grid的点击事件。尝试grid的点击事件。感谢您的回答,但我想将按钮绑定到我的ViewModel中的ICommand。请检查我的回答谢谢你的回答,但我想在我的ViewModel中将按钮绑定到ICommand。请核对我的答案