Check or Uncheck All Items in WPF CheckedListBox
18 Nov 20182 minutes to read
The WPF CheckedListBox allows users to check or uncheck all the items with a single click on the SelectAll option. The SelectAll option can be enabled or disabled using the IsSelectAllEnabled property. The selection state of the SelectAll item varies based on the checked state of the WPF CheckedListBox items. Initially, SelectAll is unchecked because no items are checked. It is checked only when all items are checked; otherwise, it is in an intermediate state.
//ViewModel.cs
class ViewModel {
public ObservableCollection<string> DaysCollection { get; set; }
public ViewModel() {
//Days added in the collection
DaysCollection = new ObservableCollection<string>();
DaysCollection.Add("Sunday");
DaysCollection.Add("Monday");
DaysCollection.Add("Tuesday");
DaysCollection.Add("Wednesday");
DaysCollection.Add("Thursday");
DaysCollection.Add("Friday");
DaysCollection.Add("Saturday");
}
}<syncfusion:CheckListBox IsSelectAllEnabled="False"
ItemsSource="{Binding DaysCollection}"
Name="checkListBox">
<syncfusion:CheckListBox.DataContext>
<local:ViewModel></local:ViewModel>
</syncfusion:CheckListBox.DataContext>
</syncfusion:CheckListBox>CheckListBox checkListBox = new CheckListBox();
checkListBox.DataContext = new ViewModel();
checkListBox.ItemsSource = (checkListBox.DataContext as ViewModel).DaysCollection;
Click here to download the sample that showcases the SelectAll option in the WPF CheckedListBox.