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

  • Home
  • SEARCH
  • 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 638743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:45:58+00:00 2026-05-13T20:45:58+00:00

Could someone help me out, to why my listbox is empty? The XmlDocument contains

  • 0

Could someone help me out, to why my listbox is empty?

The XmlDocument contains the following XML:

<Config>
  <Tabs>
    <Tab Name="Test1" />
    <Tab Name="Test2" />
  </Tabs>
</Config>

In my XAML file I have tried the following

<Window>
  <Grid>
     <ListBox DataContext="{Binding {StaticResource Data}, XPath=//Tabs}" ItemsSource="{Binding XPath=Tab/@Name}">
     </ListBox>
  </Grid>
<Window>

I know I haven’t set up the binding to name attribute but shouldn’t this display XmlDocument.XmlNode.ToString() for each Tab Node if it was working?

My C# Constructor Code behind:

InitializeComponent();
this.doc = new XmlDocument();
doc.LoadXml(config.document.OuterXml);
XmlDataProvider provider = (XmlDataProvider)Resources["Data"];
provider.Document = doc;
provider.Refresh();

With config.document.OuterXml being a valid document containing the above xml.

I got this working with procedural code using Collections, but I have been trying to figure out how to bind directly to XML.

Update: ListBox empty

Now there is no binding errors, but my listbox is coming up empty, I have double checked my XML file, and even did MessageBox.Show(provider.Document.OuterXML) and can confirm that the XmlDocument does have the correct nodes.

Thanks in advance

  • 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-13T20:45:58+00:00Added an answer on May 13, 2026 at 8:45 pm

    If you set the XmlDataProvider‘s Document property to your XmlDocument, it will refresh the bindings any time the XmlNode.NodeChanged event is raised. Since Document isn’t a dependency property, you can’t bind to it, so you have to set it in code; this should do the trick:

    In your XAML:

    <Window.Resources>
       <XmlDataProvider x:Key="Data"/>
    </Window.Resources>
    
    ...
    
    <ListBox 
        DataContext="{Binding {StaticResource Data}, XPath=Config/Tabs}"
        ItemsSource="{Binding XPath=Tab/@Name}"/>
    

    In the window’s constructor:

    InitializeComponent();
    XmlDocument d = new XmlDocument();
    d.Load("MyData.xml");
    XmlDataProvider p = (XmlDataProvider)Resources["Data"];
    p.Document = d;
    

    Now any changes you make to your XmlDocument will be reflected in the ListBox.

    Edit:

    I can’t tell you what you’re doing wrong, but perhaps you’ll be able to when you compare what you’re doing with the below, which is a complete working example.

    Window1.xaml:

    <Window x:Class="Test.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1">
        <Window.Resources>
            <XmlDataProvider x:Key="Data"/>
        </Window.Resources>
        <ListBox 
            DataContext="{Binding Source={StaticResource Data}, XPath=Config}" 
            ItemsSource="{Binding XPath=Tabs/Tab/@Name}"/>     
    </Window>
    

    Window1.xaml.cs:

    using System.Windows;
    using System.Windows.Data;
    using System.Xml;
    
    namespace Test
    {
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
    
                XmlDocument d = new XmlDocument();
                string xml = @"<Config><Tabs><Tab Name='foo'/><Tab Name='bar'/></Tabs></Config>";
                d.LoadXml(xml);
                ((XmlDataProvider) Resources["Data"]).Document = d;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 338k
  • Answers 338k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are referring to encoding/decoding of XML names, there… May 14, 2026 at 4:21 am
  • Editorial Team
    Editorial Team added an answer This is not an answer, but comments can't do this:… May 14, 2026 at 4:21 am
  • Editorial Team
    Editorial Team added an answer IE doesn't have an overall limit, although it currently applies… May 14, 2026 at 4:21 am

Related Questions

I'm just wondering why I my registered an atexit function... e.g. import atexit atexit.register(somefunc)
Could someone who is familiar with webkit please explain or point me in the
PROBLEM: Ok, I've been TRYING to follow the sample code on the MySQL Forge
I'm banging my head up against Cocoa and Xcode, and have been for months.
I have a pointer to a given class. Lets say, for example, the pointer

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.