【发布时间】:2009-02-16 02:26:25
【问题描述】:
我在 WPF 中有一个带有许多子控件的 UserControl,我想像数组一样对其进行索引。这些子控件与我不感兴趣的其他子控件位于同一网格控件中。
我希望能够以类似于以下方式索引这些控件:
someControl.Children[3];
不必避免我不感兴趣的控件。这是我所拥有的示例:
<Grid x:Name="gCalendar">
// more crap here...
<TextBlock Grid.Row="0" Grid.Column="7" TextBlock.TextAlignment="Center">Blah</TextBlock>
<Internal:DayCalendarTime Grid.Row="1" Grid.Column="0" />
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="1"/>
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="2"/>
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="3"/>
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="4" />
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="5"/>
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="6"/>
<Internal:DayCalendarCore Grid.Row="1" Grid.Column="7"/>
</Grid>
我想要一个仅由 Internal:DayTimeCore 控件组成的数组,方法是在它们周围放置某种包装控件。
这可能吗,还是我必须通过循环遍历网格的所有子节点并添加我感兴趣的类型来手动创建数组?
【问题讨论】: