0
DataGrid
을 List
에 바인딩하려고 시도하고 있으므로 목록이 자동으로 업데이트됩니다.WPF DataGrid가 List 내부의 클래스의 속성에 바인딩합니다.
private DataStorage dataStorage = new DataStorage();
XAML :
<DataGrid Name="DropFilesDataGrid" AutoGenerateColumns="False" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn x:Name="colFileName" Binding="{Binding fileName}" Header="File Name" />
<DataGridTextColumn x:Name="colFileType" Binding="{Binding fileType}" Header="File Type" />
<DataGridTextColumn x:Name="colFileLocation" Binding="{Binding fileLocation}" Header="File Location" />
</DataGrid.Columns>
</DataGrid>
DataStorage
클래스 :
public List<File> listOfFiles = new List<File>();
및 파일 클래스 :
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; }
내 xaml.cs에서
foreach (string fileDropped in files)
{
File file = new File(fileDropped);
dataStorage.AddFileToList(file);
}
목록은이 파일 객체로 가득하고, 속성이 null되지 않습니다지고 :3210
나는 통해 목록에 새 파일을 추가 할 수 있습니다.
내 문제로 인해 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')
는 공용으로 클래스 '파일'의 구성원을 변경 했습니까? –