tags:

views:

75

answers:

2

I have a UserControl in WPF with numerous child controls which I would like to index like an array. These child controls are in the same grid control as other child controls which I am not interested in.

I'd like to be able to index these controls in a way similar to:

someControl.Children[3];

With out having to avoid controls which I am not interested in. Here's a sample of what I have:

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

I would like to have an array consisting of just the Internal:DayTimeCore controls by putting some sort of wrapping control around them.

Is this possible, or will I manually have to make the array by looping through all children of the grid and adding the ones that are of the type I am interested in?

+1  A: 

You can wrap these controls inside another Grid control

Jobi Joy
There's nothing more light weight?
vanja.
+1  A: 

Another non-WPF way, Create a code behind control collection by

foreach(DayCalendarTime control in gCalendar.Children)
{ 
  controlCollection[i++] = control;
}
Jobi Joy