Hi All,
I have to bind a xml to datagrid in WPF.
Sample Input Xml
<Items>
<Item tag="Tag1" value="Value1"/>
<Item tag="Tag2" value="Value2"/>
<Item tag="Tag3" value="Value3"/>
<Items/>
I have to bind the xml to datagrid at design time such that the xpath condition should be like this.
<DataGrid Name="dgNoMethod" ItemsSource="{Binding}" AutoGenerateColumns="False" Width="Auto" Height="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Extending Unit" Binding="{Binding XPath=Attribute[value].Value}" />
<DataGridTextColumn Header="Header1" Binding="{Binding XPath=Attribute[value].Value}" />
<DataGridTextColumn Header="Header2" Binding="{Binding XPath=Attribute[value].Value}" />
<DataGridTextColumn Header="Header3" Binding="{Binding XPath=Attribute[value].Value}" />
</DataGrid.Columns>
</DataGrid>
Scenario:
I want to write a Xpath query for each column of the grid such that if the value of tag for Header1 Column is 'Tag1' then the value to be binded to that column should be Value1
So I want a XPath query somewhat like this.
<datagridtextcolumn header="Extending Unit" binding="{Binding XPath=Items/Item[@tag='Tag1']}">
AT the end the value to be binded to the Binding attribute should be Value1 if the Xpath query has 'Tag1'
Similary for other columns
Value to be binded Value2 and XPath query should have tag='Tag2'
Value to be binded Value3 and XPath query should have tag='Tag3'
Hope this clears the scenario.
Thanks, Tapas
"Happy Coding"