How do I make the last element in the foreground (top) in Collection View

AS_H 41 Reputation points
2022-09-18T04:47:15.973+00:00

Hi,
I have a collection view showing the items from the old to the new and I want it to start first with the new and then the old , how can I?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,349 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sándor Radócz 1 Reputation point
    2022-10-04T09:08:20.47+00:00

    Hello, if I understand your question correctly the following approach does the job:

    List<string> productCollection = new List<string>();  
      
    productCollection.Insert(0, "my product");  
    

    This code snippet places your new item to the first index of the collection. (works with ObservableCollection aswell)
    and this XAML right here makes sure when a new item added to your list it'll automatically set focus to top.

    <CollectionView  
                            HorizontalOptions="CenterAndExpand"  
                            ItemsSource="{Binding ProductCollection}"  
                            ItemsUpdatingScrollMode="KeepScrollOffset"  
                            VerticalScrollBarVisibility="Always">  
    </CollectionView>  
    

    Make sure that your collection is represented in the VM.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.