Search code examples
c#xamarinxamarin.formsxamarin.forms.collectionview

Is there a way to have 2 different objects following one another in a CollectionView in Xamarin.Forms?


I have a CollectionView that shows a list of Categories object like so: enter image description here

And I'd like to have a list of SubCategories to be listed right after it as if it was the same list.

I know CollectionView only takes one item but I wanted to know if there was a way to have two lists that can behave as one when you scroll

Thank you for your help


Solution

  • you can use 2 StackLayout right after each other and set BindableLayout like this :

    <StackLayout Orientation="Horizontal">
          <StackLayout Orientation="Horizontal" BindableLayout.ItemsSource="{Binding CategoryItemSource}">
              <BindableLayout.ItemTemplate>
                  <DataTemplate>
                        <!--CategoryItemTemplate-->
                    </DataTemplate>
              </BindableLayout.ItemTemplate>
          </StackLayout>
          <StackLayout Orientation="Horizontal" BindableLayout.ItemsSource="{Binding SubCategoryItemSource}">
              <BindableLayout.ItemTemplate>
                  <DataTemplate>
                      <!--SubCategoryItemTemplate-->
                  </DataTemplate>
              </BindableLayout.ItemTemplate>
          </StackLayout>
        </StackLayout>
    

    in this case first stacklayout show you category items and second stacklayout show subcategory just right after that