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

Related Questions

Could someone help me translate the following pseudo-code into code understood by Helicon Tech's
Could someone please help me out with this. I need to find the gml:pos
Could someone help me out with this JQuery? I have a bunch of list
could someone help me out with a piece of regex please? I want to
could someone help me out? I have done a straight forward MySQL query from
Could someone help me out with the correct syntax for this query please. I
I hope someone could help me on this. I want to add a month
I'm kinda stuck with this one so I hoped someone could help me. I
I've recently written this with help from SO. Now could someone please tell me
Could someone recommend any good resources for creating Graphics User Interfaces, preferably in C/C++?

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.