I have a Listbox, which houses some items. The Items are Grids which house a variety of Textblocks, buttons, etc etc.
foreach (Grid thisGrid in myListBox.SelectedItems)
{
foreach (TextBlock thisTextblock in thisGrid.Children)
{
//Do Somthing
}
}
Yet this throws an exception because there are other items than Textblock’s in there. How can I accomodate this? Thanks.
As I read it, the problem here is with the inner loop, and there being things in
Childrenthat are notTextBlocks.If LINQ is available:
otherwise: