Forum Xamarin.Forms


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.

How can I prevent ListView from flickering (in GTK only) when making any changes?

I have a Xamarin.Forms build which contains a ListView bound to an ObservableCollection. My end goal is to regularly update this ObservableCollection using a MessagingCenter subscription which is triggered by an HTTPRequest elsewhere in the app's code, but this is beside the point. I'm developing the app for use on a Raspberry Pi, and as such the GTK support has been great, but I've noticed that when adding or removing any items within the ObservableCollection, the entire list flickers. This issue only occurs in the GTK build, however. Updates are smooth in Android.

I've seen solutions for Android using things like DoubleBuffer, but since this seems like a pretty complex solution and I was having trouble understanding exactly how to implement it, I wanted to see if anyone was aware of an easier fix that was GTK specific or at least of where I could start looking for issues within the GTK build.

It should be noted that I've tried adding and removing list items from just about everywhere, including locally within the ListPageViewModel (ignoring MessagingCenter). I've included the code for the ViewModel containing the ObservableCollection and the MessagingCenter Subscription as well as the ListPage xaml. Any thoughts would be appreciated.


using MyApp.Models;
using MyApp.Views;
using System.Collections.ObjectModel;
using Xamarin.Forms;

namespace MyApp.ViewModels
    public class ListPageViewModel
        public ObservableCollection<MyItem> MyList { get; private set; } = new ObservableCollection<MyItem>();
        public MyItem SelectedMyItem { get; set; }
        INavigation Navigation;
        ListUpdater listUpdater; //This is a separate class which will be doing all of the comparisons and adding/removing on each new message

        public ListPageViewModel(INavigation MyListNavigation)
            Navigation = MyListNavigation;
            listUpdater = new ListUpdater(MyList); //passing the list by reference into the updater class
            MessagingCenter.Subscribe<object, ObservableCollection<MyItem>>(Application.Current, Constants._listUpdateContract, (sender, argument) =>

                listUpdater.AddToList(); //This method of the ListUpdater class currently only adds a new MyItem to the list
                          //I have also added and removed MyItems locally, inside a loop, without depending on the MessagingCenter      

XAML for ListView:

        <StackLayout Orientation="Horizontal">
            <ListView x:Name="MyList"
                      SelectedItem="{Binding SelectedMyItem, Mode=TwoWay}"
                      ItemsSource="{Binding MyItems}"

                    <OnPlatform x:TypeArguments="Color">
                        <On Platform="GTK" Value="White" />

                            <StackLayout Orientation="Vertical"
                                <Grid HorizontalOptions="Center"
                                    <Label Grid.Row="0"
                                           Text="{Binding TypeAndId}"
                                <Grid HorizontalOptions="Center"
                                    <Label Grid.Row="0" 
                                           Text="{Binding Current_Id, StringFormat='Current: {0}'}"/>
                                    <Label Grid.Row="0" 
                                           Text="{Binding Status}"
                                           TextColor="{Binding Status, Converter={StaticResource StatusToColorConverter}}"/>
                                    <StackLayout Grid.Row="0"
                                        <Label Text="{Binding Latitude}"/>
                                        <Label Text="{Binding Longitude}"/>
Sign In or Register to comment.