Sorry Will, but I' m beginner and I understand where the problem is, but I d'ont reach to fix it.What woult be the correct code?
Side note: It would be great if you posted only code relevant to your question. (OTOH too much code is better than too little.)
You're assigning files
which is a File
to DataGrid.ItemsSource
(indirectly through binding and DataContext
). But ItemsSource
needs a collection of items, not just one item.
If you change the second line in the event handler to:
this.dataGridElencoFiles.DataContext = new File[] { files };
the DataGrid
shows with some columns (like “Percorso” or “NomeFile”), but prints only “(Collection)” in each of them. The DataGrid
can't show that formatted as a table, because each of those collections could have different length and there is no indication that they are related.
Instead, you should have a class that represents one file and give list of those to the DataGrid
. I would rename your File
class to something like Directory
and add a method that returns collection of files from it. Or implement IEnumerable<your_file_class>
.