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 183047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:02:49+00:00 2026-05-11T15:02:49+00:00

I have a TreeView that is built on an XML file and contains a

  • 0

I have a TreeView that is built on an XML file and contains a text and an image in each TreeViewItem. Also, I have a TextBlock and an Image, that I want to bound to the selected TreeViewItem.

How can I do this?

Here is my XAML:

<Window.Resources> <HierarchicalDataTemplate DataType='Node' ItemsSource ='{Binding XPath=ChildNode}'>     <StackPanel Orientation='Horizontal'>         <Image Source='{Binding XPath=@Image}'/>         <TextBlock Text='{Binding XPath=@Name}' />     </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType='ChildNode' ItemsSource ='{Binding XPath=GrandchildNode}'>     <StackPanel Orientation='Horizontal'>         <Image Source='{Binding XPath=@Image}' />         <TextBlock Text='{Binding XPath=@Name}' />     </StackPanel> </HierarchicalDataTemplate> <DataTemplate DataType='GrandchildNode'>     <StackPanel Orientation='Horizontal'>         <Image Source='{Binding XPath=@Image}' />         <TextBlock Text='{Binding XPath=@Name}' />     </StackPanel> </DataTemplate> <XmlDataProvider x:Key='xmlNodeList' Source='XMLFile1.xml' XPath='Root'/></Window.Resources><StackPanel> <TreeView Name='treeView1' ItemsSource='{Binding Source={StaticResource xmlNodeList}, XPath=Node}' /> <TextBlock /> <Image /></StackPanel> 

And here is an XML data:

<Root> <Node Name='AAA' Image='images/1.ico' /> <Node Name='BBB' Image='images/2.ico'>     <ChildNode Name='bbb 1' Image='images/3.ico'>         <GrandchildNode Name='b 1.1' Image='images/4.ico'/>         <GrandchildNode Name='b 1.2' Image='images/5.ico'/>         <GrandchildNode Name='b 1.3' Image='images/6.ico'/>     </ChildNode>     <ChildNode Name='bbb 2' Image='images/7.ico'/>     <ChildNode Name='bbb 3' Image='images/8.ico'>         <GrandchildNode Name='b 3.1' Image='images/9.ico'/>         <GrandchildNode Name='b 3.2' Image='images/10.ico'/>     </ChildNode>     <ChildNode Name='bbb 4' Image='images/11.ico'/> </Node> <Node Name='CCC' Image='images/12.ico'>     <ChildNode Name='ccc 1' Image='images/13.ico'>         <GrandchildNode Name='c 1.1' Image='images/14.ico'/>         <GrandchildNode Name='c 2.2' Image='images/15.ico'/>     </ChildNode> </Node></Root> 
  • 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. 2026-05-11T15:02:50+00:00Added an answer on May 11, 2026 at 3:02 pm

    If you stick you TextBlock & Image inside another StackPanel to make it a bit easier you can do:

    <StackPanel DataContext='{Binding ElementName=treeView1, Path=SelectedItem}'>    <TextBlock Text='{Binding XPath=@Name}' />    <Image Source='{Binding XPath=@Image}' /> </StackPanel> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using WPF, I have a TreeView control that I want to set its ItemTemplate
I have a ASP.Net TreeView control that I am binding to an XML data
I have an XML that needs to be databound to a WPF TreeView .
I have a treeview in wpf that is built using the xaml below. It
I have built a treeview control that lists the directory structure of any drive
Scenario I have a TreeView that is bound to ObservableCollection<T> . The collection gets
I have a treeview control in a Windows Forms project that has checkboxes turned
I have a TreeView control in my WinForms .NET application that has multiple levels
I have changed the Treeview.HideSelection = false; But how do I insure that when
I have a treeview with nodes like this: Foo (1234), and want to allow

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.