Search code examples
xamllistviewxamarinxamarin.formsgrid

Xamarin forms favorite list in grid


I have a favorite pages' list in my xamarin forms app. I want it looks like sample picture. enter image description here

My favorite page is like this :

enter image description here

Xaml of listview grid : https://www.paste.tc/fav-list-grid How can I manage my xaml ?


Solution

  • Yes! Exactly! And I save these favorite pages to sqlite. I don't write row and colum. How can I manage this row and columns ?

    For this,you can use CollectionView to achieve this.

    In XAML, a CollectionView can display its items in a vertical grid by setting its ItemsLayout property to VerticalGrid:

    <CollectionView ItemsSource="{Binding Monkeys}"
                    ItemsLayout="VerticalGrid, 2">
        <CollectionView.ItemTemplate>
            <DataTemplate>
              <!--  For simplicity, omit the additional code -->
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
    

    Alternatively, this layout can also be accomplished by setting the ItemsLayout property to a GridItemsLayout object whose Orientation property is set to Vertical:

    <CollectionView ItemsSource="{Binding Monkeys}">
        <CollectionView.ItemsLayout>
           <GridItemsLayout Orientation="Vertical"
                            Span="2" />
        </CollectionView.ItemsLayout>
        ...
    </CollectionView>
    

    For more information, please check document: Vertical grid.