I have a TreeView that binds to XML data and one DataGrid that binds to SelectedItem of that TreeView using this XAML code:
<DataGrid Name="Dg1">
<DataGrid.ItemsSource>
<Binding ElementName="treeView1" Path="SelectedItem.Elements[Book]" />
</DataGrid.ItemsSource>
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding Path=Attribute[id].Value}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Attribute[name].Value}"/>
</DataGrid.Columns>
</DataGrid>
and this XML:
<Books>
<Book id="123" name="Big Cat" type="t1" />
<Book id="124" name="First Man" type="t1" />
<Book id="125" name="Number One" type="t2" />
</Books>
This works fine but I want to filter the set of Books by some condition using XPath after Path but this doesn’t work:
XPath="Book[@type='t1']"
What is the best solution for this problem?
Or is it possible to use ‘SelectedEtem‘ in XPath instead of using Path?!
Use data context to get selected item then in itemssource you can narrow the results by type.
EDIT:
Regards