Wednesday, September 26, 2012

How do I access the UI elements within an ItemsControl?

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?

Answers & Comments...

Answer: 1

Parse through it with a foreach statement?

eg:

foreach (ChildObject c in ParentObject.Children)

by : Peterhttp://stackoverflow.com/users/1658168

Answer: 2

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

by : John Gardnerhttp://stackoverflow.com/users/13687




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog