private Dictionary<string, ObservableCollection<string>> dataDictionary = new Dictionary<string, ObservableCollection<string>>();
public Dictionary<string, ObservableCollection<string>> DataDictionary {
get {return dataDictionary; }
set {
dataDictionary = value;
OnPropertyChanged(nameof(DataDictionary));
}
}
The dataDictionary is filled by the following method:
private void LoadDictionary() {
Dictionary<string, ObservableCollection<string>> data = new Dictionary<string, ObservableCollection<string>>();
data["TimeStamp"] = new ObservableCollection<string>();
for (int i = 0; i < recordingData.Data.Channels.Length; i++) {
data[recordingData.MetaData.Channels[i].ChannelId] = new ObservableCollection<string>();//In my Sample I have to ChannelIds "A","C"
}
for (int i = 0; i < recordingData.MetaData.Common.RecordCount; i++) {
data["TimeStamp"].Add(i.ToString());
for (int j = 0; j < recordingData.Data.Channels.Length; j++) {
data[recordingData.MetaData.Channels[j].ChannelId].Add(recordingData.Data.Channels[j].Values[i].ToString());//Channels contains several thousand double values
}
}
dataDictionary = data;
}
Then I have a page that contains the grid:
<syncfusion:SfDataGrid x:Name="grid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"/>
In the codebehind I am trying to set the data:
this.viewModel = viewModel;
grid.ColumnSizer = ColumnSizer.Star;
grid.AutoGenerateColumns = false;
foreach (var key in viewModel.DataDictionary.Keys) {
GridTextColumn col = new GridTextColumn();
col.HeaderText = key;
col.MappingName = $"DataDictionary[{key}]";
grid.Columns.Add(col);
}
grid.ItemsSource = viewModel.DataDictionary;
The grid is displayed with the right columns but the data from the ObservableCollections is not shown.
I see only three empty line (I guess this is caused by the dictionary that is containing three keys).
What do I have to change to get the data from the ObservableCollections displayed?
Attached you find a screenshot of my grid.
Thanks
Jens