title: Load XmlDataProvider in code
body: <p>Im puzzled</p>
  
  <p>I have xml document</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Reports&gt;
    &lt;Report Id="AAAAA-ABBB"&gt;
      &lt;DocId&gt;10110001&lt;/DocId&gt;
      &lt;DocName&gt;ESP North Casing&lt;/DocName&gt;
      &lt;DocType&gt;2010-01-01&lt;/DocType&gt;
      &lt;Status&gt;1&lt;/Status&gt;
      &lt;CreatedById&gt;1&lt;/CreatedById&gt;
      &lt;SiteId&gt;1&lt;/SiteId&gt;
      &lt;Language&gt;1&lt;/Language&gt;
      &lt;Updated&gt;2011-01-01&lt;/Updated&gt;
      &lt;Published&gt;2011-01-01&lt;/Published&gt;
      &lt;FilePath&gt;c:\\reports\20011001.docx&lt;/FilePath&gt;
    &lt;/Report&gt;
    &lt;Report Id="AAAAA-ABBC"&gt;
      &lt;DocId&gt;10110002&lt;/DocId&gt;
      &lt;DocName&gt;ESP South Casing&lt;/DocName&gt;
      &lt;DocType&gt;2010-01-01&lt;/DocType&gt;
      &lt;Status&gt;1&lt;/Status&gt;
      &lt;CreatedById&gt;1&lt;/CreatedById&gt;
      &lt;SiteId&gt;1&lt;/SiteId&gt;
      &lt;Language&gt;1&lt;/Language&gt;
      &lt;Updated&gt;2011-01-01&lt;/Updated&gt;
      &lt;Published&gt;2011-01-01&lt;/Published&gt;
      &lt;FilePath&gt;c:\\reports\20011001.docx&lt;/FilePath&gt;
    &lt;/Report&gt;
  &lt;/Reports&gt;
  </code></pre>
  
  <p>If i define a static xmldataprovider like</p>
  
  <pre><code> &lt;UserControl.Resources&gt;
  
      &lt;XmlDataProvider x:Key="ReportData"
                 Source="../DesignData/report.xml"
                 XPath="Reports/Report" /&gt;
  
      &lt;DataTemplate x:Key="teamItemTemplate"&gt;
          &lt;Label Content="{Binding XPath=DocId}"/&gt;
      &lt;/DataTemplate&gt;
  &lt;/UserControl.Resources&gt;
  </code></pre>
  
  <p>And show document in a listbox</p>
  
  <pre><code>&lt;ListBox x:Name="ReportListBox" Margin="60,12,114,64" DockPanel.Dock="Left"
               ItemsSource="{Binding 
           Source={StaticResource ReportData}}"
  
               ItemTemplate="{StaticResource teamItemTemplate}"
               IsSynchronizedWithCurrentItem="True"
               Visibility="Visible" SelectionMode="Single"&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>I can see the data in the listbox</p>
  
  <p>If i do the same in code and load xmldataprovider in my viewmodel</p>
  
  <pre><code>  private XmlDataProvider GetXMLReports()
          {
                string filePath = Directory.GetCurrentDirectory() + @"\Data\report.xml";
                XmlDataProvider provider = new XmlDataProvider(); 
                  System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); 
                doc.Load(filePath); 
                provider.Document = doc; 
                provider.XPath = "Reports/Report";
                //Reports = _provider;
  
                return provider;
  
          }
  
          public XmlDataProvider Reports
          {
              get { return _provider; }
              set
              {
                  _provider = value;
                  this.RaisePropertyChanged(() =&gt; this.Reports);
              }
          }
  </code></pre>
  
  <p>If i set datacontext to viewmodel and bind to property Report</p>
  
  <pre><code>&lt;ListBox x:Name="ReportListBox" Margin="60,12,114,64" DockPanel.Dock="Left"
                   ItemsSource="{Binding Path=Reports}"
  
                   ItemTemplate="{StaticResource teamItemTemplate}"
                   IsSynchronizedWithCurrentItem="True"
                   Visibility="Visible" SelectionMode="Single"&gt;
      &lt;/ListBox&gt;
  </code></pre>
  
  <p>Nothing is shown , any ideas.</p>