Jordan
Jordan

Reputation: 9901

How do I access the UI elements within an ItemsControl?

I have subclassed a Silverlight ItemsControl into a SlideShow control. This works fine when I hard-code the item elements in the XAML directly. But if I use a DataTemplate, how do I access the UI elements for each item?

Upvotes: 0

Views: 1258

Answers (2)

John Gardner
John Gardner

Reputation: 25116

The ItemsControl may create new items for them as items come and go, so you have to use ItemsControl.Items to get each data item, then use ItemsControl.ItemContainerGenerator.ContainerFromItem (or other methods on the ItemContainerGenerator to find the UI element for that item that was created by the DataTemplate

see: http://msdn.microsoft.com/en-us/library/system.windows.controls.itemcontainergenerator(v=vs.95).aspx

Upvotes: 3

Peter Dongan
Peter Dongan

Reputation: 2306

Parse through it with a foreach statement?

eg:

foreach (ChildObject c in ParentObject.Children)

Upvotes: 0

Related Questions