Forum Xamarin Xamarin.Forms

CollectionView nested into a ListView

I've tried to nest a CollectionView inside a ListView.... I was able to visualize all what i needed but now I cannot reach the click event on a single cell of a single CollectionView inside the list. This is my xaml code:

<ListView  x:Name="MainListView" VerticalOptions="FillAndExpand">
                        <CollectionView Margin="10" SelectionMode="Single" ItemsSource="{Binding singleList}" FlowDirection="LeftToRight" ItemsLayout="HorizontalList">
                                    <Grid Padding="10" Margin="10">
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                        <Frame BackgroundColor="White" Grid.RowSpan="2" CornerRadius="5" Padding="10">
                                            <Image Source="{Binding ImageName}" Aspect="AspectFill" HeightRequest="100" WidthRequest="100" />
                                        <Label Grid.Column="1" Text="{Binding Name}" FontAttributes="Bold" />
                                        <Label Grid.Row="1" Grid.Column="1" Text="{Binding Date}" VerticalOptions="End" />
                                        <Image Grid.Row="2" Grid.Column="0" Source="shop" HeightRequest="20" WidthRequest="20" />

I suppose I have to use the SelectionChangedCommand event inside the Collection, but I don't understand... how!! Some help?


  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 2019

    t now I cannot reach the click event on a single cell of a single CollectionView inside the list.

    You mean the click event on Grid or the Labels or the entire ViewCell ?

    I think you could add TapGestureRecognizer on the layout or control you want to reach .

    For example

                     <Grid Padding="10" Margin="10">
  • GiulianoCandrevaGiulianoCandreva ITMember ✭✭

    Thank for the reply, but the problem is that command function not firing...
    I've added this:

    But the breakpoint in code behind don't stop the execution.... the event does not start!!!

  • ColeXColeX Member, Xamarin Team Xamurai

    Maybe there is conflict between with ListView.ItemSelected event and your custom event .

    Try to disable the selected event in a listview ,refer

    <ListView ItemSelected="ListView_ItemSelected" />
    private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
          var list = (ListView)sender;
          list.SelectedItem = null;
Sign In or Register to comment.