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; }