GridView ItemClick未检测到? [英] GridView ItemClick not detected?
本文介绍了GridView ItemClick未检测到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在使用Template 10 Hamburger开发一个UWP应用程序。我创建了一个GridView并试图添加项目点击属性,但是没有检测到该事件,并且从不调用事件处理程序。
I am developing a UWP application, using Template 10 Hamburger. I created a GridView and tried to add item click property, but the event is not detected, and the event handler is never called.
源代码如下:
BookViewModel.cs:
BookViewModel.cs:
public void NavigateToDetails(string url)
{
NavigationService.Navigate(typeof(Views.DetailPage), url);
}
public void BookGroups_OnItemClick(object sender, ItemClickEventArgs e)
{
var bookHeader = (BookGroup)e.ClickedItem;
NavigateToDetails(bookHeader.url);
}
Book.xaml:
Book.xaml:
<Page.DataContext>
<vm:BookViewModel x:Name="ViewModel" />
</Page.DataContext>
<Page.Resources>
<CollectionViewSource x:Key="BookViewSource"
IsSourceGrouped="True"
Source="{Binding BookGroups}"
ItemsPath="url" />
</Page.Resources>
<GridView
Grid.Row="1"
Name="GridView1"
Padding="18"
ItemsSource="{Binding Source={StaticResource BookViewSource}}"
IsItemClickEnabled="True"
ItemClick="{x:Bind ViewModel.BookGroups_OnItemClick}"
>
<GridView.ItemTemplate>
<DataTemplate>
<Grid Width="250" Height="250">
<Border VerticalAlignment="Bottom" Background="#AA000000">
<TextBlock Text="{Binding name}" Margin="12" Foreground="White"/>
</Border>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}" Margin="-12,0,0,0"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
感谢您的帮助。
推荐答案
看起来你的DataTemplate中的Grid没有对事件做出反应。尝试给它一个背景(甚至透明就可以),或者将它设置为
true 的IsHitTestVisible。
It looks like the Grid in your DataTemplate is not reacting to events. Try giving it a Background (even Transparent is OK), or set it IsHitTestVisible to true.
这篇关于GridView ItemClick未检测到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文