So, I hope the title is pretty self-explanatory but as always, gonna describe it better. I'm trying to put a lot of checkboxes into a list, so then I can use their index to uncheck them when I have another one checked.
A brief part of my XAML since it's kinda long and repetitive mostly
<Expander Header="Tercer Ciclo" FontWeight="Bold" Width="auto" Height="auto">
<StackPanel>
<Expander Header="9° Grado" Margin="20,0,0,0">
<StackPanel>
<CheckBox x:Name="NovA" Margin="40,0,0,0" Content="Noveno A" />
<CheckBox x:Name="NovB" Margin="40,0,0,0" Content="Noveno B" />
<CheckBox x:Name="NovC" Margin="40,0,0,0" Content="Noveno C"/>
<CheckBox x:Name="NovD" Margin="40,0,0,0" Content="Noveno D"/>
<CheckBox x:Name="NovE" Margin="40,0,0,0" Content="Noveno E"/>
</StackPanel>
</Expander>
This structure just repeats itself another 7 times or so. The thing is, when I select one, I want the other ones to uncheck. It doesn't really affect the correct functioning of the program, it's just more aesthetic and to orient the user.
Before you start shouting that I should use that or this. I have tried:
- Using radio buttons, but since it's a list IN another list, it didn't work out too well.
- I searched how to create a list to insert the windows' controls, and found kind of an answer but it was meant for WinForms and I have no idea how to do it on WPF since it has differents methods.
- Tried to insert the CheckBox's name manually, one by one... No way I'm finishing that; even then the
foreach
syntax for the controls...
I took this as a reference for the Code behind: [Assign checkboxes to an checkbox-array using a for loop in C# ]
I have this already, it was a code that I saw that was almost exactly what I wanted, but again, meant for WinForms so the foreach
syntax kind of doesn't fit WPF
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<CheckBox> listCheck = new List<CheckBox>();
foreach (Control checkbox in //Invoke the window's Controls, don't know the syntaxis)
{
//Add the Checkbox's x:Name on the list...
}
}
Sorry if I made this post so long, but I've been cracking my head around this for weeks now, and haven't found some clue to what I'm missing... I'm pretty new to WPF and C# in general, so yeah, kinda lost.