sbondo1234
Member
- Joined
- Jan 21, 2020
- Messages
- 8
- Programming Experience
- 1-3
I have a DataTemplate that holds:
I add the template to a ListBox like:
The addRule function adds a template to the ListBox, which works.
I have an Unchecked event on the checkbox which I want to use to check if all the other checkboxes are unchecked. If every checkbox is unchecked then it should disable buttons I have.
I can't figure out how to loop over all the CheckBoxes in the ListBox and check if they are ticked or not. How would I do this?
XML:
<DataTemplate x:Key="hostListItem">
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="hostCheckBox" Margin="0 0 5 0"
Unchecked="hostCheckBox_Unchecked"
Checked="hostCheckBox_Checked">
</CheckBox>
<TextBlock Text="{Binding Path=Name}"></TextBlock>
</StackPanel>
</DataTemplate>
I add the template to a ListBox like:
C#:
public class Host
{
public string Name
{
get;
set;
}
public string Address
{
get;
set;
}
}
C#:
public partial class MainWindow : Window
{
private void addRule()
{
ObservableCollection<Host> hostData = new ObservableCollection<Host>();
// Add data to Host structure
hostData.Add(new Host()
{
Name = host,
Address = address
});
// Add new host to listbox
hostsListBox.Items.Add(hostData);
}
}
The addRule function adds a template to the ListBox, which works.
I have an Unchecked event on the checkbox which I want to use to check if all the other checkboxes are unchecked. If every checkbox is unchecked then it should disable buttons I have.
I can't figure out how to loop over all the CheckBoxes in the ListBox and check if they are ticked or not. How would I do this?