Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you set the <code>XmlDataProvider</code>'s <code>Document</code> property to your <code>XmlDocument</code>, it will refresh the bindings any time the <code>XmlNode.NodeChanged</code> event is raised. Since <code>Document</code> isn't a dependency property, you can't bind to it, so you have to set it in code; this should do the trick:</p> <p>In your XAML:</p> <pre><code>&lt;Window.Resources&gt; &lt;XmlDataProvider x:Key="Data"/&gt; &lt;/Window.Resources&gt; ... &lt;ListBox DataContext="{Binding {StaticResource Data}, XPath=Config/Tabs}" ItemsSource="{Binding XPath=Tab/@Name}"/&gt; </code></pre> <p>In the window's constructor:</p> <pre><code>InitializeComponent(); XmlDocument d = new XmlDocument(); d.Load("MyData.xml"); XmlDataProvider p = (XmlDataProvider)Resources["Data"]; p.Document = d; </code></pre> <p>Now any changes you make to your <code>XmlDocument</code> will be reflected in the <code>ListBox</code>.</p> <p><strong>Edit:</strong></p> <p>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.</p> <p>Window1.xaml:</p> <pre><code>&lt;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"&gt; &lt;Window.Resources&gt; &lt;XmlDataProvider x:Key="Data"/&gt; &lt;/Window.Resources&gt; &lt;ListBox DataContext="{Binding Source={StaticResource Data}, XPath=Config}" ItemsSource="{Binding XPath=Tabs/Tab/@Name}"/&gt; &lt;/Window&gt; </code></pre> <p>Window1.xaml.cs:</p> <pre><code>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 = @"&lt;Config&gt;&lt;Tabs&gt;&lt;Tab Name='foo'/&gt;&lt;Tab Name='bar'/&gt;&lt;/Tabs&gt;&lt;/Config&gt;"; d.LoadXml(xml); ((XmlDataProvider) Resources["Data"]).Document = d; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload