Freigeben über


How Do I.... Linq directly into an ItemCollection?

I have this:

private void LoadSupportSolutionsSection(ItemCollection itemCollection, XElement category)
{
// Solution, url att, Title, Description.
var solutions = from sol in category.Elements("Solution")
select new TreeViewItem {
Header = sol.Element("Title").Value,
Tag = sol.Attribute("url").Value,
ToolTip = new ToolTip()
{
Content=sol.Element("Description").Value,
StaysOpen=true
}
};

    foreach (TreeViewItem item in solutions)
{
itemCollection.Add(item);
}
}

A very simple linq query spun from from XML returned from a Web service. The TreeViewItem is a WPF tree view item. So how do I write the select portion such that it inserts into the TreeView.Items collection each newly created TreeViewItem?

Anyone have an idea? I have two or three creative ones, but I have tried them out yet. Any suggestions appreciated....