title: WPF, read data from XmlDataProvider in C#
body: <p>I want a <code>TreeView</code> with checkboxes and I'm trying to follow <a href="http://www.codeproject.com/KB/WPF/TreeViewWithCheckBoxes.aspx" rel="nofollow noreferrer">this tutorial</a>.  However, in it, he creates all his content for the <code>TreeView</code> at runtime.  I have an XML file that I have accessible as an <code>XmlDataProvider</code> in my XAML:</p>
  
  <pre><code>&lt;XmlDataProvider Source="XmlData/Versions.xml" XPath="//*[count(*)=0]"
                   x:Key="versionsXml" /&gt;
  </code></pre>
  
  <p>I have a view model class with <code>IsChecked</code> and <code>Name</code> properties, and I want to use this to represent nodes in my XML:</p>
  
  <pre><code>&lt;Versions&gt;
    &lt;Version name="1.0"&gt;
      &lt;Version name="1.0.001" /&gt;
      &lt;Version name="1.0.002" /&gt;
    &lt;/Version&gt;
  &lt;/Versions&gt;
  </code></pre>
  
  <p>My <code>TreeView</code> will display leaf nodes (i.e., 1.0.001 and 1.0.002) with a checkbox.  How can I populate my <code>TreeView</code> with not the <code>XmlDataProvider</code>'s content directly, but rather a <code>List&lt;MyViewModel&gt;</code>?  I can create a property in my <code>DataContext</code> that returns a <code>List&lt;MyViewModel&gt;</code>, then bind my <code>TreeView</code> to that property, but I don't know how, in a C# property getter, to read in the XML data from the <code>XmlDataProvider</code>.  When I use <code>TryFindResource</code> and cast the <code>object</code> result to <code>XmlDataProvider</code>, the <code>Document</code> and <code>Data</code> properties are null for my <code>versionsXml</code> resource (defined in <code>&lt;UserControl.Resources&gt;</code>).</p>