I'm trying to create setup a simple CellEditor for a column so that it has a combo box with the 8 directions of the compass rose (NW, N, NE, E, SE, S, SW, W), and I need to do this in code (not in XAML), but I'm having difficulty in translating the technique. The SolidFoundation example gives the following XAML code:
<xcdg:CellEditor x:Key="employeeEditor">
<xcdg:CellEditor.EditTemplate>
<DataTemplate>
<ComboBox BorderThickness="0"
BorderBrush="Transparent"
Background="Transparent"
Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(TextElement.Foreground)}"
MaxHeight="28"
VerticalContentAlignment="Top"
SelectedValuePath="EmployeeID"
ItemsSource="{Binding Source={x:Static Application.Current},Path=Employees}"
ItemTemplate="{StaticResource employeeDataTemplate}"
SelectedValue="{xcdg:CellEditorBinding}">
<ComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="TextElement.Foreground"
Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
</Style>
</ComboBox.Resources>
</ComboBox>
</DataTemplate>
</xcdg:CellEditor.EditTemplate>
Where I'm getting particularly hung up is the 4th line. I'm not yet an expert at converting XAML to C#, but if you look at the overloaded constructors on the DataTemplate object, it seems to take either an object which is supposed to be a type, or a string for XML. But, in the XAML above, it seems as though the actual combo box is being passed in.
Basically, I want to do something like this (BTW, is there a better way to post code? Tag perhaps? I tried to read the forum FAQ but it came up as HTML when rendered in both Firefox and IE, so I'm not sure how to do it.):
ComboBox comboBox = new ComboBox();
comboBox.Items.Add("NW");
comboBox.Items.Add("N");
comboBox.Items.Add("NE");
comboBox.Items.Add("E");
comboBox.Items.Add("SE");
comboBox.Items.Add("S");
comboBox.Items.Add("SW");
comboBox.Items.Add("W");
dataGridControl.Columns[0].CellEditor.EditTemplate.DataType = comboBox;
But I get a run-time error that the object is not a type or a string.
So my question is, what is the translation from XAML to C# in this instance, as it is clearly not what I think it should be.
Also, is there a simple (as in a couple lines of code, not a complete, complex application) example of how to setup different editors (comboboxes, buttons, checkboxes, etc.) for columns? Preferably in code (XAML is only useful to a point). That would be most helpful.
Thanks!