我有一个包含2列的网格,并在其中填充了图像。点击时如何获取图像在网格中的位置?
postman.setNextRequest(null)
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"
</Grid.GestureRecognizers>
答案 0 :(得分:1)
我建议为此使用一个软件包,以Listview的方式轻松检测点击:AiForms.CollectionView
您可以简单地做到:
<ai:GridCollectionView
ItemsSource="{Binding ItemsSource}" TouchFeedbackColor="Yellow"
ColumnWidth="100" ColumnHeight="1.0"
IsGroupingEnabled="true" GroupHeaderHeight="36" >
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ai:ContentCell>
<Label Text="{Binding Category}" BackgroundColor="#E6DAB9" />
</ai:ContentCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ai:ContentCell>
<Label Text="{Binding Name}" />
</ai:ContentCell>
</DataTemplate>
</ListView.ItemTemplate>
</ai:GridCollectionView>
并像列表视图一样检测点击:
void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
{
var photo = e.Item as PhotoItem;
DisplayAlert("", $"ItemTapped {photo.Category} {photo.Title}", "OK");
}