Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF DataGrid绑定到列表中类的属性_C#_Wpf_Binding_Data Binding - Fatal编程技术网

C# WPF DataGrid绑定到列表中类的属性

C# WPF DataGrid绑定到列表中类的属性,c#,wpf,binding,data-binding,C#,Wpf,Binding,Data Binding,我正在尝试将一个数据网格绑定到一个列表,以便在列表执行时自动更新 在my xaml.cs中: private DataStorage dataStorage = new DataStorage(); xaml: 和文件类: private string fileName { get; set; } private long fileSize { get; set; } private string fileImage { get; set; } private string fileLocat

我正在尝试将一个
数据网格
绑定到一个
列表
,以便在列表执行时自动更新

在my xaml.cs中:

private DataStorage dataStorage = new DataStorage();
xaml:

和文件类:

private string fileName { get; set; }
private long fileSize { get; set; }
private string fileImage { get; set; }
private string fileLocation { get; set; }
private string fileType { get; set; }
我通过以下方式向列表中添加新文件:

foreach (string fileDropped in files)
{
    File file = new File(fileDropped);
    dataStorage.AddFileToList(file);
}
列表中正在填充这些文件对象,并且属性不为null

我的问题是让
DataGridView
用它更新

我的错误:

System.Windows.Data Error: 40 : BindingExpression path error: 'fileName' property not found on 'object' ''File' (HashCode=1820782)'. BindingExpression:Path=fileName; DataItem='File' (HashCode=1820782); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'fileType' property not found on 'object' ''File' (HashCode=1820782)'. BindingExpression:Path=fileType; DataItem='File' (HashCode=1820782); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'fileLocation' property not found on 'object' ''File' (HashCode=1820782)'. BindingExpression:Path=fileLocation; DataItem='File' (HashCode=1820782); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

使用
observedcollection
而不是
List
,还可以使用
public
文件的成员

public ObservableCollection<File> listOfFiles = new ObservableCollection<File>();

您是否已将类“File”的成员更改为公共成员?
System.Windows.Data Error: 40 : BindingExpression path error: 'fileName' property not found on 'object' ''File' (HashCode=1820782)'. BindingExpression:Path=fileName; DataItem='File' (HashCode=1820782); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'fileType' property not found on 'object' ''File' (HashCode=1820782)'. BindingExpression:Path=fileType; DataItem='File' (HashCode=1820782); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'fileLocation' property not found on 'object' ''File' (HashCode=1820782)'. BindingExpression:Path=fileLocation; DataItem='File' (HashCode=1820782); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
public ObservableCollection<File> listOfFiles = new ObservableCollection<File>();
  public string fileName { get; set; }
  public long fileSize { get; set; }
  public string fileImage { get; set; }
  public string fileLocation { get; set; }
  public string fileType { get; set; }