Hi,
My XML structure is like this:
="1.0"="utf-8"
<categories>
<category name="Panels">
<category name="Grid"></category>
<category name="Border"></category>
<category name="Stack Panel"></category>
<category name="Canvas"></category>
<category name="Wrap Panel"></category>
</category>
<category name="Shape">
<category name="Rectangle"></category>
<category name="Elipse"></category>
<category name="Line"></category>
</category>
<category name="Others">
<category name="Button"></category>
<category name="Check Box"></category>
<category name="Radio Button"></category>
<category name="Text Block"></category>
<category name="Text Box"></category>
<category name="Password Box"></category>
</category>
</categories>
and I binded this to a treeview like this:
List<Products> categories = new List<Products>();
XDocument categoriesXML = XDocument.Load("Products.xml");
categories = select.LoadDimensions(categoriesXML.Element("categories"));
this.MyTreeView.ItemsSource = categories;
public List<Products> LoadDimensions(XElement element)
{
return (from Products in element.Elements("category")select new Products()
{
Name = Products.Attribute("name").Value,
SubCategories = this.LoadDimensions(Products)
}).ToList();
}
And the treeview is with check boxes. If any check box is selected i need the parent of that child node, parent node and root using linq which needs to return List<>. So that i can bind to another treeview. I wrote like this but it is giving an error: In the below mentioned linq assume rectangle checkbox is selected. So i need rectangle, shape and category to bind it to another treeview.
List<Products> listProd = (from elm in categoriesXML.Element("category").Attribute("name").Value == "Shape"
where elm.Attribute("name").Value == "Rectangle"
select new Products
{
Name = elm.Attribute("name").Value
}).ToList();
I need a
LINQ
query for the selected nodes. For example if i had selected Rectangle, it is a child of shape and the parent of the shape is categories like this structure i need a list. So that i can bind it to another treeview.
Can some body let me know regarding this issue.
Regards,
Amarendra.