This question ties to my previous question but is more specific. Say I have two ComboBoxes, one populated with product names, the other empty. When a product is chosen, I want the second ComboBox to be filled with data related to that product. I have XML like the following:
<Products>
<Product name="MyProduct1">
<Components>
<Component name="MyComponent1"/>
<Component name="MyComponent2"/>
...more Component nodes...
</Components>
</Product>
...more Product nodes...
</Products>
What I was hoping is that I could somehow set the XPath
on the Component ComboBox such that it gets all the Components/Component
nodes from the Product
node whose @name
attribute is equal to the currently selected value in the Product ComboBox. Is this possible? How would I do it? Here's what I have in my XAML so far:
<ComboBox Height="23" HorizontalAlignment="Left" Margin="138,116,0,0"
Name="cbo_product" VerticalAlignment="Top" Width="120"
ItemsSource="{Binding Source={StaticResource productsXml}}"
DisplayMemberPath="@name"/>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="138,151,0,0"
Name="cbo_component" VerticalAlignment="Top" Width="201"
DisplayMemberPath="@name">
<ComboBox.ItemsSource>
<!-- Currently gets all Component nodes--want it to get only those
associated with the selected Product -->
<Binding Source="{StaticResource productsXml}"
XPath="Components/Component"/>
</ComboBox.ItemsSource>
</ComboBox>
The Product ComboBox is filled with product names like MyProduct1, so that part is fine. It's the dependent Component ComboBox I need help with.