I have created a list and showing in collectionview
<CollectionView.ItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<StackLayout HorizontalOptions="FillAndExpand" Padding="16,0"> <Frame x:Name="frame" HasShadow="False" Padding="8" HeightRequest="64" CornerRadius="10" BackgroundColor="{DynamicResource ColorInteraction1Lightest}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="2*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="30" /> <ColumnDefinition Width="2" /> <ColumnDefinition Width="64" /> <ColumnDefinition Width="24" /> </Grid.ColumnDefinitions> <Label Text="{Binding LeaveSummaryTitle}" HorizontalTextAlignment="Start" FontSize="{DynamicResource FontSize3}" TextColor="{DynamicResource ColorInteraction1Base}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" /> <Label Text="{Binding LeaveCount}" HorizontalTextAlignment="Start" FontSize="{DynamicResource FontSize10}" TextColor="{DynamicResource ColorInkBase}" Grid.Row="1" Grid.Column="0" /> <BoxView Grid.Row="1" Grid.Column="1" BackgroundColor="{DynamicResource ColorInkBase}" /> <Label Text="{Binding LeaveDate}" HorizontalTextAlignment="Start" FontSize="{DynamicResource FontSize3}" TextColor="{DynamicResource ColorInkBase}" Grid.Row="1" Grid.Column="2" /> <Image x:Name="image" Margin="0,4" Aspect="AspectFit" HeightRequest="24" WidthRequest="24" Source="icon_info" Grid.Row="1" Grid.Column="3" effects:TooltipEffect.Position="Top" effects:TooltipEffect.BackgroundColor="Navy" effects:TooltipEffect.Text="{Binding ToolTipText}" effects:TooltipEffect.HasTooltip="True" > </Image> </Grid> <Frame.GestureRecognizers> <TapGestureRecognizer Command="{Binding InfoCommand}" CommandParameter="{x:Reference image}"/> </Frame.GestureRecognizers> </Frame> </StackLayout> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> Viewmodle =>
public DelegateCommand InfoCommand { get; set; }
InfoCommand = new DelegateCommand(ShowInfo);
private void ShowInfo(Picker picker)
{
}
Whenever I click on the item of the collectionview nothing happening. As per my code it should call ShowInfo method.
Please help
Answers
Try to use ICommand instead of DelegateCommand. Or use
Tapped
event to achieve the gesture function.Tutorial:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/tap
Sample code:
https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/workingwithgestures-tapgesture/