xamlxamarin.formsxamarin.forms.listview

When I used TextCell in listview, listview items are nulls


In my page I use a Listview, which is show files names in an directory.

When I used TextCell in Listview, Listview items are null.

My code for Listview items is:

            DirectoryInfo di = new DirectoryInfo(myDirectory);
            FileInfo[] files = di.GetFiles();

            if (Directory.Exists(myDirectory))
            {
                for (int i = 0; i < files.Length; i++)
                {
                    lstFiles.Add(i + 1 + ". " + files[i].Name);
                }
            }
            lstviewsFile.ItemsSource = lstFiles;

My xaml:

Can you help me?


Solution

  • lstFiles is your ItemsSource - each row in the list is just a string (presumably, you didn't actually show that code)

    so your binding should be

    <TextCell Text="{Binding .}" ... />