I implemented this by creating a DataTemplate as mentioned elsewhere in the forum:
<DataTemplate x:Key="RuntimeContentTemplate">
<ContentControl Loaded="ContentControl_Loaded" />
</DataTemplate>
Then in the ContentControl_Loaded event I had the appropriate control based on information in the object assigned to each row. The idea here is that we have a class (Property) that defines how we want this value presented in the grid.
private void ContentControl_Loaded(object sender, RoutedEventArgs e)
{
var contentControl = sender as ContentControl;
if (contentControl != null)
{
var parentCell = contentControl.ParentOfType<GridViewCell>();
var column = parentCell.Column as GridViewDataColumn;
var row = parentCell.ParentRow as GridViewRow;
if (row != null)
{
IProperty p1 = row.Item as IProperty;
if(p1 != null)
{
Binding binding = new Binding("Value");
binding.Mode =
BindingMode.TwoWay;
switch(p1.ControlType.ToUpper())
{
case "TEXTBOX":
TextBox textBox = new TextBox();
textBox.SetBinding(TextBox.TextProperty, binding);
contentControl.Content = textBox;
textBox.Margin =
new Thickness(0);
break;
case "DATEPICKER":
RadDatePicker datePicker = new RadDatePicker();
datePicker.SetBinding(RadDatePicker.SelectedDateProperty, binding);
contentControl.Content = datePicker;
break;
case "CHECKBOX":
CheckBox checkBox = new CheckBox();
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
checkBox.Margin =
new Thickness(0);
contentControl.Content = checkBox;
break;
case "COMBOBOX":
RadComboBox comboBox = new RadComboBox();
comboBox.SetBinding(RadComboBox.SelectedItemProperty, binding);
comboBox.Margin =
new Thickness(0);
switch (p1.Type.ToUpper())
{
case "STRING":
foreach (string item in ((Property<string>)p1).Constraints)
{
comboBox.Items.Add(item);
}
break;
}
contentControl.Content = comboBox;
break;
}
}
}
}I have not found out how to get the controls to fill the cell space. I have set the Margin of each control to 0 with no effect. I have tried setting the controls width to the column width but doesn't make any difference. I have attached a picture showing how the controls do not fill the space of the cell.