List directory files in a DataGrid

后端 未结 5 1870
悲哀的现实
悲哀的现实 2021-01-22 00:10

I have searched many topics and can\'t find an answer on using the WPF DataGrid to list file name contents from a directory. I am able to output the contents in a <

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-22 01:01

    Instead of:

    object[] AllFiles = new DirectoryInfo(path).GetFiles().ToArray();
    

    use

    List AllFiles = new DirectoryInfo(path).GetFiles().ToList();
    MyDataGrid.ItemSource = Allfiles;
    

    This will automatically bind the files to the DataGrid.

提交回复
热议问题