WPF DataGrid showing empty double cells but correct column headers
I am trying to populate a WPF datagrid but it's only showing the column headers and the content cells of the first(!) column. All other cells are empty:
The DataGrid is defined like this:
<DataGrid ItemsSource="{Binding Classifications, Mode=OneWay}"
AutoGenerateColumns="True" HeadersVisibility="Column" />
Classifications is defined in the code-behind file like this:
public DataView Classifications
{
get
{
return ClassificationDataTable.GetTable(myData).DefaultView
}
}
and finally this is my data generator:
public static class ClassificationDataTable
{
public stat开发者_如何学Pythonic DataTable GetTable(List<Classification> classifications)
{
DataTable table = new DataTable();
// build columns
table.Columns.Add("FruitPrototype", typeof (string));
foreach (var featureComparison in classifications[0].FeatureComparisons)
table.Columns.Add(featureComparison.FeatureName, typeof (double));
// add rows
foreach (var classification in classifications)
{
object[] values = new object[classification.FeatureComparisons.Count+1];
values[0] = classification.FruitPrototype.FruitType;
for (int i = 0; i < classification.FeatureComparisons.Count; i++)
values[i + 1] = classification.FeatureComparisons[i].NormalizedDistance;
table.Rows.Add(values);
}
return table;
}
}
I verified the binding and can confirm that the DefaultView of the DataTable is indeed bound to the ItemsSource of my DataGrid. Also, the double values that should be shown in the grid are != 0.
What am I missing here?
I figured it out with the help of Jimmy W's question: I had some brackets and dots in the column names which somehow broke the binding of the cells. Changing the values of the feature names in
table.Columns.Add(featureComparison.FeatureName, typeof (double));
fixed my problem.
精彩评论