Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:10:29+00:00 2026-05-27T20:10:29+00:00

I have a TreeView that binds to XML data and one DataGrid that binds

  • 0

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?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:10:30+00:00Added an answer on May 27, 2026 at 8:10 pm

    Use data context to get selected item then in itemssource you can narrow the results by type.

    <DataGrid DataContext="{Binding ElementName=treeView1, Path=SelectedItem.Elements[Book]}" ItemsSource="{Binding XPath=Book[@type\=\'t1\'] }" AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="200" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Id" Binding="{Binding Path=Attribute[Id].Value}"/>
                    <DataGridTextColumn Header="Name" Binding="{Binding Path=Attribute[name].Value}"/>
                </DataGrid.Columns>
    
            </DataGrid>
    

    EDIT:

     <Grid>
            <Grid.Resources>
                <XmlDataProvider x:Key="InventoryData" XPath="Inventory/Books">
                    <x:XData>
                        <Inventory xmlns="">
                            <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>
                        </Inventory>
                    </x:XData>
                </XmlDataProvider>
            </Grid.Resources>
            <Button DataContext="{StaticResource InventoryData}" Tag="{Binding}" Content="Button" Height="23" HorizontalAlignment="Left" Margin="409,134,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    
    
            <DataGrid DataContext="{Binding ElementName=button1, Path=Tag}" ItemsSource="{Binding XPath=Book[@type\=\'t1\'] }" AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="200" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Id" Binding="{Binding Path=Attributes[id].Value}"/>
                    <DataGridTextColumn Header="Name" Binding="{Binding Path=Attributes[name].Value}"/>
                </DataGrid.Columns>
    
            </DataGrid>
    
        </Grid>
    

    Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagrid that binds its data from SelectedItem of a TreeView. The
I have a ASP.Net TreeView control that I am binding to an XML data
This is the test xml that i am using: <categories> <category id=1 name=Test1> <category
I have a TreeView that is generated in code, and will look like this
I have a treeview in wpf that is built using the xaml below. It
Say I have a 3-level data-bound WPF TreeView like this one: a aa aaa
I currently have a treeview that displays data using a hierarchicaldatatemplate and when the
I try to have a treeview that browse potentially cyclic hierarchical data. This means
Using WPF, I have a TreeView control that I want to set its ItemTemplate
I have a TreeView databound to a CollectionViewSource Groups collection. This is so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.