Allow me to first introduce the classes that I am using:
public class Assessment
{
public List<NormDefinition> Definitions {get;set;}
public List<Parameter> Parameters {get;set;}
}
public class NormDefinition
{
public string ColumnName {get;set;}
}
public class Parameter
{
public string Name {get;set;}
public List<NormValue> Norms {get;set;}
}
public class NormValue
{
public NormDefinition Definition {get;set;}
public string Value {get;set;}
}
The user is navigating through a sort of wizard and has to complete some tasks to create an Assessment.
The first step is defining one or more NormDefinitions. It has some more settings than shown above but the others are irrelevant to the problem.
The second step is to define one or more Parameters. However, the user can also add some values for the previously defined NormDefinitions. I am trying to do this by creating a DataGrid with ItemsSource = {Binding Assessment.Parameters}, so I know that the source for each binding is the Parameter object that is bound to that row.
When the second screen gets focus, some code adds a column for each NormDefinition where the user might fill in the value. The creation of the columns looks like this:
private void CreateNormDefinitionColumns()
{
foreach (var definition in Assessment.Definitions)
{
DataGridTextColumn column = new DataGridTextColumn();
column.Header = definition.ColumnName;
column.Binding = new Binding()
{
// Add a binding to:
// Parameter.Norms.Single(norm => norm.Definition == definition).Value;
}
ParameterDataGrid.Columns.Add(column);
}
}
Please help me with a solution to set up this binding.
To take it one step further, in case the .Single() does not return a result, I would like the NormValue object to be created and added to the parameter.