I have 2 DataGrid and one XmlDataProvider for XML-file. XML-file structure looks like this:
<Setting>
<Element Name="..." Offset="..." ID="...">
<Item Name="..." Type="..." Count="..." ID="..." />
<Item Name="..." Type="..." Count="..." ID="..." />
<Item Name="..." Type="..." Count="..." ID="..." />
...
</Element>
<Element Name="..." Offset="..." ID="...">
<Item Name="..." Type="..." Count="..." ID="..." />
<Item Name="..." Type="..." Count="..." ID="..." />
</Element>
...
</Setting>
I need to display the values of attributes of all Elements in first DataGrid, and the values of attributes of all Items in second DataGrid using same XmlDataProvider.
XAML to display the values of attributes of all Elements in first DataGrid:
...
<Grid.DataContext>
<XmlDataProvider x:Name="xml_setting" XPath="/Setting/Element"/>
</Grid.DataContext>
<DataGrid ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="*" Binding="{Binding XPath=@Name}"/>
<DataGridTextColumn Header="Offset" Width="80" Binding="{Binding XPath=@Offset}"/>
<DataGridTextColumn Header="ID" Width="80" Binding="{Binding XPath=@ID}"/>
</DataGrid.Columns>
</DataGrid>
...
I tried to set the XmlDataProvider XPath value in "/Setting" and the Columns XPath values in "/Element/@Name", "/Element/@Offset" and "/Element/@ID", but only first Element is displayed.
How can I working with one XmlDataProvider to binding to different columns of different DataGrids to display the values of attributes of different nodes of the XML-file?