views:

577

answers:

2

I have created a WPF tooklit datagrid in C# and the ItemsSource is set in the XAML. The columns are automatically generated.

I am trying to do a datagrid that uses an ObservableCollection, pretty much like what is on this website.

At the bottom you will find a sample that you can download (here is the link)

My problem is that I'm trying to change certain properties of a specific column (example: Datagrid.Columns[index].Property) but this does not seem to work since the the column count is always equal to 0. Therefore, I cannot change the properties by using the index that I want to use because there seems to be nothing in the Columns collection. Yet at runtime there are columns that are displayed.

So, how can it be possible that column count is equal to 0?

and

How can I change the properties of a specific column in my situation?

+1  A: 

According to several forum experiences, columns aren't accessible via the Columns property if they are autogenerated. I don't know why this is so, but it has been seen before.

kek444
The properties of Columns at a certain index are accessible but there is no column in the Columns collection because they are not generated yet. So it will fail on you if you try to do so.
Partial
+2  A: 

I have finally found how! The reason that the column count equals 0 is because the columns are not yet generated. In order to change the properties I have to use the AutoGeneratedColumns event and change the properties in there.

Partial