I'm using Silverlight 5.1.30514.0 with Windows 8, and I have a case, in which depending of a field in a table I need to present different amounts of CheckBox, if the field is 4, then 4 CheckBox, if the field is 6, then 6 CheckBox, and this field can be 4, 6, 10 or 12, then I make at Resources:
<DataTemplate x:Name="chkField4" DataType="ContentControl">
<Grid Name="grd">
<Border BorderBrush="Black" BorderThickness="1" Margin="0,0,0,0" Background="DarkSeaGreen" />
<CheckBox Content="2" Name="chk2" Grid.Column="1" Margin="20,20,20,20" Checked="CheckBox_Checked" />
<CheckBox Content="1" Name="chk1" Grid.Column="1" Margin="20,60,20,20" Checked="CheckBox_Checked"/>
<CheckBox Content="4" Name="chk4" Grid.Column="1" Margin="80,20,20,20" Checked="CheckBox_Checked"/>
<CheckBox Content="3" Name="chk3" Grid.Column="1" Margin="80,60,20,20" Checked="CheckBox_Checked"/>
</Grid>
</DataTemplate>
And another:
<DataTemplate x:Name="chkField6" DataType="ContentControl">
<Grid Name="grd">
<Border BorderBrush="Black" BorderThickness="1" Margin="0,0,0,0" Background="DarkSeaGreen" />
<CheckBox Content="2" Name="chk2" Grid.Column="1" Margin="20,20,20,20" Checked="CheckBox_Checked" />
<CheckBox Content="1" Name="chk1" Grid.Column="1" Margin="20,60,20,20" Checked="CheckBox_Checked"/>
<CheckBox Content="4" Name="chk4" Grid.Column="1" Margin="80,20,20,20" Checked="CheckBox_Checked"/>
<CheckBox Content="3" Name="chk3" Grid.Column="1" Margin="80,60,20,20" Checked="CheckBox_Checked"/>
<CheckBox Content="6" Name="chk6" Grid.Column="1" Margin="140,20,20,20" Checked="CheckBox_Checked"/>
<CheckBox Content="5" Name="chk5" Grid.Column="1" Margin="140,60,20,20" Checked="CheckBox_Checked"/>
</Grid>
</DataTemplate>
And 2 more similar (chkField10, chkField12) for each case. And I put a ContentControl:
<ContentControl Name="chk" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>
And at behind code depending of a field, if field=4:
chk.ContentTemplate = chkField4;
Now, I want to Access to each ComboBox in order to review if is checked, something like:
if (chk2.IsChecked) ...
if (chk1.IsChecked) ...
But, the problem is: chk1, chk2, ... are not available to ask for them, and I would like to make a generic cycle with a "for" or "foreach" 1 to n, where n is the amount of CheckBox in the ContentControl in a time
I don't know how I can do this, or if I have done is right, someone could guide me?
I'm realy new in this environment, thanks