I have an xml file which contains multiple hierarchical data required for a WPF application. My objective is to first filter the data using the ComboBox and finally select the data inside the AttributeUp and AttributeDown tags into the code.
<?xml version = "1.0" encoding="utf-8"?>
<MenuItems xmlns="">
<Menu Name="menu1">
<SubMenu Name = "submenu1">
<ItemsList>
<Item Name = "item1">
<AttributeUp>DataUp</AttributeUp>
<AttributeDown>DataDown</AttributeDown>
</Item>
</SubMenu>
</Menu>
</MenuItems>
Below is the code to add XmlDataProvider to static resource.
<Window.Resources>
<XmlDataProvider x:Key="updownItems" Source="./updownItemsList.xml" XPath="MenuItems/Menu" IsInitialLoadEnabled="True" IsAsynchronous="False"/>
</Window.Resources>
Below is how I am filtering the data
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="Level1" Width="35" Margin="0,0,0,0"></Label>
<ComboBox x:Name="cmbBoxToplevel" IsEditable="True" SelectedIndex="0" Width="110"
Margin="0,0,0,0" HorizontalAlignment="Right"
ItemsSource="{Binding Source={StaticResource updownItems}}"
DisplayMemberPath="@Name" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Level2" Margin="0,0,0,0"></Label>
<ComboBox x:Name="cmbBoxSecondLevel" IsEditable="True" Width="110" SelectedIndex="0"
Margin="0,0,0,0" HorizontalAlignment="Right"
DataContext="{Binding Path=SelectedItem, ElementName=cmbBoxToplevel}"
ItemsSource="{Binding XPath=./Menu}" DisplayMemberPath="@Name" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Level3" Margin="0,10,0,0"></Label>
<ComboBox x:Name="cmbBoxJanya" IsEditable="True" Width="110" SelectedIndex="0"
Margin="0,10,0,0" HorizontalAlignment="Right" DataContext="{Binding Path=SelectedItem,
ElementName=cmbBoxSecondLevel}" ItemsSource="{Binding XPath=./ItemsList/Item}"
DisplayMemberPath="@Name" />
</StackPanel>
</StackPanel>
With these, I am able to filter the xml tag names into different comboboxes. What I need to achieve is to access the contents of AttributeUp and AttributeDown directly into the C# code behind (MainWindow). I do not want to use any WPF elements to store these parameters. It it possible without writing a separate code for xml parsing.