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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:18:18+00:00 2026-05-23T20:18:18+00:00

Question may need to be edited since I don’t think I necessarily know the

  • 0

Question may need to be edited since I don’t think I necessarily know the best way to do this.

Current config of my WPF usercontrol.
I have a XmlDataProvider that contains some static XML Elements that I use to populate a TreeView control.
I currently use a HierarchicalDataTemplate to bind to a TreeViewItem

    <HierarchicalDataTemplate x:Key="SiteTemplate" ItemsSource="{Binding XPath=pci}">
        <TextBlock Text="{Binding XPath=@Name}"/>
    </HierarchicalDataTemplate>
    <Style TargetType="TreeViewItem">
        <Setter Property="IsExpanded" Value="True"/>
    </Style>

TreeView control

 <TreeView ItemsSource="{Binding Source={StaticResource SharePointSites}}" 
                              ItemTemplate="{StaticResource SiteTemplate}" 

I would like to replace the current static resource with data that is loaded from a xml file at runtime. Additionally I want the user to be able to modify the nodes of the treeview at runtime and have those values written back to the same xml file.
I have been reading up about using the MVVM pattern and creating an IObservable class. Can someone point me in the right direction?

Edit:
Perhaps I’ve asked this question in a sub-optimal way. Can anyone recommend improvements or make edits to improve the quality of the question in anyway?

  • 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-23T20:18:19+00:00Added an answer on May 23, 2026 at 8:18 pm

    I have no access to my Visual Studio environment so the code below will be full of compilation errors… So please treate this as a pseudo code…

    Assuming your Xml structure is something like this….

    <MyItem Name="Root"> 
        <MyItem Name="ABC"/> 
        <MyItem Name="PQR"> 
            <MyItem Name="IJK"/> 
        </MyItem> 
        <MyItem Name="XYZ"/> 
    </MyItem> 
    
    1. Bind your ItemsSource thru a converter , say MyXmlToObjectDataSourceConverter.

      <TreeView ItemsSource="{Binding Source={StaticResource SharePointSites},
             Converter={StaticResource MyXmlToObjectDataSourceConverter}}" ... />
      
    2. In MyXmlToObjectDataSourceConverter.Convert() method return this…

      public object Convert(...) 
      { 
          return new ObservableCollection<XmlNodeWrapper>(
              ((XmlDataProvider)value).Document.SelectNodes("MyItem").Select( 
                  d => new XmlNodeWrapper(d)).ToList()) 
      }
      
    3. XmlNodeWrapper class will maintain the ‘node’ internally so that when updates take place thru property Setters,
      you can update the node based attribute back… like this…

      public class XmlNodeWrapper : INotifyPropertyChanged
      { 
          private XmlNode node; 
          private ObservableCollection<XmlNodeWrapper> children; 
      
          public XmlNodeWrapper(XmlNode node) 
          { 
              this.node = node; 
          } 
      
          public ObservaleCollection<XmlNodeWrapper> Children 
          { 
              get 
              { 
                  if (children == null) 
                  { 
                      this.children 
                          = new ObservableCollection<XmlNodeWrapper>( 
                              this.node.ChildNodes.Select( 
                                  d => new XmlNodeWrapper(d)).ToList()); 
                  } 
      
                  return children; 
              } 
          } 
      
          public string Name 
          { 
              get 
              { 
                  return node.Attributes["Name"]; 
              } 
      
              set 
              { 
                  node.Attributes["Name"] = value; 
                  this.PropertyChanged["Name"]; 
              } 
          } 
      
          public event PropertyChangedEventHandler PropertyChanged; 
      
          private void PropertyChanged(String info) 
          { 
              if (PropertyChanged != null) 
              { 
                  PropertyChanged(this, new PropertyChangedEventArgs(info)); 
              } 
          }
      } 
      
    4. Then replace all XPath attributes in your XAML with standard Path.

      <HierarchicalDataTemplate x:Key="SiteTemplate"
          ItemsSource="{Binding Path=Children}"> 
              <TextBlock Text="{Binding Path=Name}"/> 
      </HierarchicalDataTemplate>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a stupid question to ask, but still I need to know
Now this may seem like a silly question, but I need to know how
This question may look to be very simple but i don't know the answer.
So I understand this may come across as a open question, but I need
I'm new to C#, so this may be a basic question. What I need
The answer to this question may be obvious but I need to ask it
This question may be stupid, but I don't really see how to resolve it
This was a hard question for me to summarize so we may need to
This question may sound kinda weird but actually, I need to convince my mangement
I may need to implement this sometime in the future, but I think the

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.