title: How to bind XmlDataProvider property of viewmodel with XmlDataProvider in view?
body: <p>I am trying to display some xml data in TreeView. Xml data is provided by ViewModel's property of type XmlDataProvider. However, I am unable to bind it with TreeView. I am using XmlDataProvider in XAML and unable to bind the ViewModel Property with XmlDataProvider in XAML. Below is code snippet:</p>
  
  <pre><code>public class MainViewModel : ViewModelBase {
  
  
      private static XmlDataProvider  xDoc;
      public static XmlDataProvider  XDoc {
        get {
          return xDoc;
        }
        set {
          xDoc = value;
          RaisePropertyChanged( "XDoc" );
        }
  
      }
  
  
      public MainViewModel( ) {
        Data d = new Data( );
        d.int1 = 12;
        d.int2 = 20;
        d.str = "Hello World";
  
        XmlSerializer serializer = new XmlSerializer( d.GetType( ) );
        StringWriter strWriter = new StringWriter( );
        serializer.Serialize( strWriter, d );
        XDoc = new XmlDataProvider { Document =XDocument.Parse( strWriter.ToString( ) ).ToXmlDocument (), XPath="child::node"} ;    
      }
    }
  </code></pre>
  
  <p>Xaml code:  </p>
  
  <pre><code>&lt;XmlDataProvider x:Key="xmlDP" Source="{ x:Static A:MainViewModel.XDoc}"  XPath=""&gt;
      &lt;/XmlDataProvider&gt;
  &lt;TreeView Grid.Row="2" Grid.ColumnSpan="2" Name="xmlTree" 
         DataContext="{StaticResource xmlDP}" ItemsSource="{Binding}" ItemTemplate="{StaticResource treeViewTemplate}"/&gt;
  </code></pre>
  
  <p>I am using mvvm light framework. When I try, I get exception that XDoc property should be static and I do not want to make it static. </p>
  
  <p>If define my X:data inside XmlDataProvider within xaml file then treeview works:</p>
  
  <pre><code> &lt;XmlDataProvider x:Key="xmlDP" XPath=""&gt;
              &lt;x:XData&gt;
                  &lt;Employees&gt;
                      &lt;Employee Name="Steven Ballmer" DOB="1-Mar-1956"&gt;
                          &lt;Title&gt;CEO&lt;/Title&gt;
                      &lt;/Employee&gt;
                  &lt;/Employees&gt;
              &lt;/x:XData&gt;
          &lt;/XmlDataProvider&gt;
  
   &lt;TreeView Grid.Row="2" Grid.ColumnSpan="2" Name="xmlTree" 
             DataContext="{StaticResource xmlDP}" ItemsSource="{Binding}" ItemTemplate="  {StaticResource treeViewTemplate}"/&gt;
  </code></pre>