0

I have a Silverlight user control that contains an ItemsControl that renders a StackPanel containing another user control for each item in the data source, the XAML is as follows:

<Grid x:Name="LayoutRoot">
    <ItemsControl ItemsSource="{Binding}" x:Name="ValuesItemSource">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel x:Name="ValuesPanel" Background="Transparent" Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <controls:MyCustomControl DataContext="{Binding}"  x:Name="Value" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

How would I reference the collection of MyCustomControls (Values) in the code behind of this user control?

(I have an event handler registered in the code behind of this control and I want to invoke a method of each "MyCustomControl" when the event fires)

kristian
  • 22,731
  • 8
  • 50
  • 78

1 Answers1

1

You need to ask the itemsControl.ItemContainerGenerator for this. See here for an example.

David Lynch
  • 1,716
  • 15
  • 15
  • Thanks David. Your comment led me to http://stackoverflow.com/questions/980120/finding-control-within-wpf-itemscontrol which is exactly what I was after. – kristian Jul 13 '10 at 01:21