Just use ListBoxItem
. The CheckListBox
control (and any ItemsContainer-derived control) isn't required to define its own item classes. You can use any ContentControl-derived class but ListBoxItem
provides usefull properties like IsSelected.
A much better solution is to bind the CheckListBox
to a collection of your own classes and set bindings to properties of your classes. In fact, this is shown in the description of the CheckListBox
control itself. Just note that you have to bind SelectedItemsOverride
to a list of selected items instead of SelectedItems
For example, assuming I have the following in my MainWindow.xaml.cs
public MainWindow()
{
DataContext = this;
MyItems = new List<string> { "a", "b", "c" };
JustSelectedItems = new List<string>();
InitializeComponent();
}
I can create a CheckBoxList
like this:
<xctk:CheckListBox
ItemsSource="{Binding MyItems}"
SelectedItemsOverride="{Binding JustSelectedItems}" />
and each time I check/uncheck an item it is added or removed from JustSelectedItems.
Typically, you would use an MVVM framework that would set the correct DataContext for each control, but for this simple example I simple told the form to bind to itself