I'm having trouble setting XML data as the ItemsSource for my DataGrid Combobox.
Below is my XML code:
<?xml version="1.0" standalone="yes"?>
<Table>
<FRUIT>
<edible>True</edible>
<Types main="Apple">
<Type>Fuji</Type>
<Type>Gala</Type>
</Types>
</FRUIT>
<FRUIT>
<edible>True</edible>
<Types main="Banana">
<Type>Burro</Type>
<Type>Red</Type>
</Types>
</FRUIT>
</Table>
Next is the XAML code for the WPFtoolkit DataGrid Combobox:
<Custom:DataGridTemplateColumn Header="Fruits" Width="300">
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cboFruit"/>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
Before I had to load the data to a ComboBox, I just put the XML data into a DataSet and set the DataGrid's DataContext to the first table in the DataSet.
Now that won't work since I'm trying to put each type of the fruits into the ComboBox.
I can change anything in the XML to get it to work. Let me know if you need more info.
Thanks in advance!
Posted below is the full XAML for my CustomDataGrid (WPFtoolkit):
<Window.DataContext>
<XmlDataProvider x:Name="FruitData" XPath="fruits/fruit" />
</Window.DataContext>
<Grid>
<Custom:CustomDataGrid x:Name="dgFruits" AutoGenerateColumns="False" Margin="5" CanUserAddRows="True"
ItemsSource="{Binding XPath=fruits/fruit}"><!--Here is confusion-->
<Custom:DataGrid.Columns>
<!--Edible-->
<Custom:DataGridTextColumn Header="Edible" Binding="{Binding XPath=edible}"/>
<!--Fruit-->
<Custom:DataGridTemplateColumn Header="Fruit Types" Width="300">
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding XPath=types/type}"/><!--This works fine on a combobox outside of the DataGrid-->
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
</Custom:CustomDataGrid>
</Grid>