2014-11-03 2 views
0

DataGridList에 바인딩하려고 시도하고 있으므로 목록이 자동으로 업데이트됩니다.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') 

답변

1

사용 ObservableCollection<File> 대신 List<File>는 또한 클래스 Filepublic 멤버를 사용합니다.

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

는 공용으로 클래스 '파일'의 구성원을 변경 했습니까? –

관련 문제