I would like to bind some objects to a datagrid
in WPF
. I would VERY MUCH like to avoid DataTable!
Consider the following code:
public ObservableCollection<ObservableCollection<DataPoint>> GridItems { get; set; }
public class DataPoint : INotifyPropertyChanged
{
public float Value { get; set; }
public float OriginalValue { get; set; }
public bool Highlighted { get; set; }
public SolidColorBrush HighlightColor { get; set; }
...
}
XAML:
<toolkit:DataGrid ItemsSource="{Binding GridItems}" />
When we bind this to a DataGrid
instead of getting one DataPoint object per cell we get one column with Count
as the property shown. I have tried 2D arrays, custom types (inheriting from ObservableCollection<DataPoint>
), HierarchicalDataTemplate
but nothing seems to be working.
I do not know before-hand how many columns there are going to be, but it will always be the same number and type for every row. Any suggestions?