How do I access the children of an ItemsControl?
https://stackoverflow.com/questions/1000345
OTHER TIPS
See if this helps you out:
foreach(var item in itemsControl.Items)
{
UIElement uiElement =
(UIElement)itemsControl.ItemContainerGenerator.ContainerFromItem(item);
}
There is a difference between logical items in a control and an UIElement
.
To identify ItemsControl
's databound child controls (like a ToggleButton
), you can use this:
for (int i = 0; i < yourItemsControl.Items.Count; i++)
{
ContentPresenter c = (ContentPresenter)yourItemsControl.ItemContainerGenerator.ContainerFromItem(yourItemsControl.Items[i]);
ToggleButton tb = c.ContentTemplate.FindName("btnYourButtonName", c) as ToggleButton;
if (tb.IsChecked.Value)
{
//do stuff
}
}
I'm assuming ItemsControl.Items[index]
doesn't work, then?
I'm not being funny, and I haven't checked for myself - that's just my first guess. Most often a control will have an items indexer property, even if it's databound.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow