title: WPF, XML databinding into dependent/cascading ComboBoxes
body: <p>I have an XML file with the following structure:</p>
  
  <pre><code>&lt;Products&gt;
    &lt;Product name="MyProduct1"&gt;
      &lt;Components&gt;
        &lt;Component name="MyComponent1"&gt;
          &lt;SubComponents&gt;
            &lt;SubComponent name="MySubComponent1"/&gt;
            &lt;SubComponent name="MySubComponent2"/&gt;
            ...more SubComponent nodes...
          &lt;/SubComponents&gt;
        &lt;/Component&gt;
        ...more Component nodes...
      &lt;/Components&gt;
    &lt;/Product&gt;
    ...more Product nodes...
  &lt;/Products&gt;
  </code></pre>
  
  <p>I'm trying to create a WPF app that has a ComboBox with the Product names in it.  I am completely new to WPF so I don't know if I'm going about things the right way.  When a Product is chosen, a second ComboBox should be populated with all the Components for that Product.  And when a Component is chosen, a third ComboBox should be populated with all the SubComponents for that Component.</p>
  
  <p>I don't know how to set up a dependency between ComboBoxes except to populate the dependent ComboBox inside an event handler triggered by the independent ComboBox.  This seems to imply I need to be able to read the XML in C#, so I have <a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx" rel="nofollow noreferrer"><code>[Serializable]</code></a> classes for <code>Products</code>, <code>Product</code>, <code>Component</code>, and <code>SubComponent</code>.  However, I was trying to do XML databinding in my XAML:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;XmlDataProvider Source="Products.xml"
                       XPath="Products/Product"
                       x:Key="productsXml"/&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>I'm currently not seeing a list of Product names in my first ComboBox, whose XAML is the following:</p>
  
  <pre><code>&lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="138,116,0,0"
            Name="cbo_product" VerticalAlignment="Top" Width="120"
            ItemsSource="{Binding Source=productsXml, XPath=@name}"
            SelectionChanged="product_SelectionChanged"/&gt;
  </code></pre>
  
  <p>The Products XML should be read-only--the user won't be able to change any values in the XML from the app.  I just want to read the XML data and display it in the app.</p>
  
  <p>I have a few questions:</p>
  
  <ol>
  <li>Am I going about this correctly?  Having a standalone XML file from which my WPF app reads, having <code>[Serializable]</code> classes representing the nodes in the XML file for the purpose of extracting data from those nodes in C#, using an event handler to code dependencies between ComboBoxes, etc.</li>
  <li>Why don't my product names, e.g., MyProduct1, show up in my ComboBox?  Currently it just shows up empty.</li>
  <li>It seems almost like having <code>[Serializable]</code> classes for representing my XML nodes is redundant/unnecessary since XAML already has the <code>XmlDataProvider</code>/XPath stuff.  Is this the case?</li>
  </ol>
  
  <p><strong>Edit:</strong></p>
  
  <p>Updated my ComboBox XAML to the following and now I see my list of Product names in the ComboBox, thanks to <a href="https://stackoverflow.com/questions/3388759/wpf-xml-databinding-into-dependent-comboboxes/3388822#3388822">decyclone's answer</a>:</p>
  
  <pre><code>&lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="138,116,0,0"
            Name="cbo_product" VerticalAlignment="Top" Width="120"
            ItemsSource="{Binding Source={StaticResource productsXml}}"
            DisplayMemberPath="@name"
            SelectionChanged="product_SelectionChanged"/&gt;
  </code></pre>