question

ASH-1598 avatar image
0 Votes"
ASH-1598 asked SndorRadcz-6928 answered

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


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?

dotnet-xamarin
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Did you mean you want to order your ItemSource of CollectionView?

If so, You could use OrderBy method of LINQ to do it.

Please refer to Enumerable.OrderBy Method to get more details.

0 Votes 0 ·

I have not heard from you for a couple of days. Please let me know if there is anything that I can help here.

0 Votes 0 ·

1 Answer

SndorRadcz-6928 avatar image
0 Votes"
SndorRadcz-6928 answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.