5

When i scroll the list fast, each cell appears as black before data is loaded.If i scroll slowly data black cells won't appear. This behavior is happening only for Xamarin UWP project. Please find the below image for reference.enter image description here

Renjith
  • 682
  • 4
  • 19

2 Answers2

3

Fixed the issue by writing custom ViewCell and by making use of native datatemplate. Now there is no black cells on fast scrolling. I am posting my answer so that someone may find it useful.

For eg: If you have a list of names to be displayed follow:

First add custom viewcell as follows

        public class CustomViewCell : ViewCell
       {
        public static readonly BindableProperty NameProperty =
            BindableProperty.Create("Name", typeof(string), typeof(CustomViewCell), "");

        public string Name
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

       }

Now add the ListView in XAML as follows:

            <ListView 
            ItemsSource="{Binding Products}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <custom:CustomViewCell  Name="{Binding Name}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
            </ListView>

Then you have to write the DateTemplate style in App.xaml of UWP project as follows:

        <ResourceDictionary>
        <DataTemplate x:Key="CustomTemplate">
            <Grid Padding="10">
                <TextBlock  Foreground="#333333" FontSize="14" VerticalAlignment="Center" Text="{Binding Name"/>
            </Grid>
        </DataTemplate>
        </ResourceDictionary>

Finally write a CustomRenderer to replace the native viewcell to our our ListView.

    public class CustomViewCellRenderer : ViewCellRenderer
    {
    public override Windows.UI.Xaml.DataTemplate GetTemplate(Cell cell)
    {
        return App.Current.Resources["CustomTemplate"] as Windows.UI.Xaml.DataTemplate;
    }
    }

Now list works perfectly without any black cell rendering issue.

Renjith
  • 682
  • 4
  • 19
  • Hi @Renjith, still that black screen is flickered in the listview using the custom view cell. Could you help me please? – Riyas May 07 '19 at 14:18
2

This is not a problem with your code. When you scroll too fast the system doesn't have time to render the cells as quickly as you are scrolling, so the black cell appears.

Luccas Clezar
  • 1,032
  • 10
  • 18
  • luccas-clezar Yes thats right. This issue is happening only UWP. Is there any to overcome this issue. – Renjith Jun 06 '17 at 04:10
  • 1
    Unfortunately I don't think so. I tried several ways of increasing performance (like trying to remove the bindings and do the changes of the cell in the PropertyChanged or BindingContextChanged) but I didn't notice any performance increase. – Luccas Clezar Jun 06 '17 at 14:52
  • Hi have fixed the issue by customizing the ViewCell. I have written the customrenderer to fix the issue. Now there is no black cells on fast scrolling. I have added my answer below. – Renjith Jun 13 '17 at 05:14