Rodrigo Silva
Rodrigo Silva

Reputation: 432

WPF Datagrid - DataBinding C#

I'm fresh new to WPF, and I've been trying to populate a DataGrid, but it shows no values...

As you can see: http://i.epvpimg.com/EJ0Bh.png

Code:

List<FileI> files = new List<FileI>();
foreach (string file in Directory.GetFiles("profileSettings"))
{
    files.Add(new FilI( { fileName = file, fileSize = new FileInfo(file).Length }));
}

dgFilesToExtract.ItemsSource = files;

I checked the folder, there are 2 files, and I placed a BP before the ItemsSource property is set, and the list has items.

What am I doing wrong?

Thanks in advance

Upvotes: 0

Views: 4313

Answers (4)

Jordy van Eijk
Jordy van Eijk

Reputation: 2766

About the Blurry Font problem. There are lots of topics on this take a look at this one

Upvotes: 0

LeftyCoder
LeftyCoder

Reputation: 432

It looks like you are setting the ItemsSource property of the grid in code AND binding it in the XAML. Try removing the binding statement in the XAML.

Upvotes: 0

brunnerh
brunnerh

Reputation: 184296

Your file class only contains fields but you can only bind to properties. Read the documentation.

Upvotes: 2

Nitin Purohit
Nitin Purohit

Reputation: 18580

In your File class define properties over the variables and set AutogenerateColumns = true on your datagrid

Upvotes: 1

Related Questions