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:
xaml that works
<ListView x:Name="lstviewsFile"
ItemsSource="{Binding lstFiles}"
SeparatorColor="#448AFF"
SelectionMode="Single"
ItemSelected="lstviewsFile_ItemSelected">
</ListView>
xaml that doesn't work
<ListView x:Name="lstviewsFile"
SeparatorColor="#448AFF"
SelectionMode="Single"
ItemSelected="lstviewsFile_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding lstFiles}" TextColor="#FFFFFF"></TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Can you help me?
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 .}" ... />