C# 以编程方式从代码隐藏中引用ItemsControl呈现的项

C# 以编程方式从代码隐藏中引用ItemsControl呈现的项,c#,silverlight,xaml,silverlight-4.0,code-behind,C#,Silverlight,Xaml,Silverlight 4.0,Code Behind,我有一个Silverlight用户控件,其中包含一个ItemsControl,该控件呈现一个StackPanel,其中包含数据源中每个项目的另一个用户控件,XAML如下所示: <Grid x:Name="LayoutRoot"> <ItemsControl ItemsSource="{Binding}" x:Name="ValuesItemSource"> <ItemsControl.ItemsPanel> &l

我有一个Silverlight用户控件,其中包含一个
ItemsControl
,该控件呈现一个
StackPanel
,其中包含数据源中每个项目的另一个用户控件,XAML如下所示:

<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>

如何引用此用户控件背后代码中的
MyCustomControls
s)集合


(我在该控件的代码隐藏中注册了一个事件处理程序,我想在事件触发时调用每个“MyCustomControl”的方法)

您需要向itemsControl.ItemContainerGenerator询问此问题。请参阅以获取示例。

谢谢David。你的评论让我找到了我想要的东西。