Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Collection View Highlight the last added item

Hi I am using collection view with signalR , data will add for my collection view , i want to show different color for last added item to the list. Thanks

Answers

  • stXamDevstXamDev Member ✭✭✭

    make a boolean field IsLastItem in your model then when you add the last item or you can check via traversing set that field to true. Make a data trigger for that field and set a different color for the last field

  • YelinzhYelinzh Member, Xamarin Team Xamurai

    Collection View Highlight the last added item

    In the CollectionView, the selected item will highlight. For the function, you could set the last item as the selected item.

    Check the code:
    Page.xaml

    <CollectionView x:Name="collectionView"
                    ItemsSource="{Binding GroupDataCollection}" 
                    SelectionMode="Single" ...>
        ...
    </CollectionView>
    

    Page.xaml.cs

    var viewModel = new CustomViewModel();
    viewModel.DataCollection.Add(new CustomModel { ... });
    
    collectionView.SelectedItem = viewModel.DataCollection[viewModel.DataCollection.Count - 1];
    
Sign In or Register to comment.