Reputation: 3966
I am using the Extended WPF Toolkit 2.0.0 to design a CheckListBox
. I need to design
checkbox items for it, but for some reason, the CheckListBoxItem
doesn't exist. Or at least, my project can't find the reference anywhere. That's funny, cause this tutorial explicitly uses those, which seems to work fine. I was thinking it might be a different version, but then why would anyone remove it?
The following is a snippet of my code:
<Window x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctkToolkit="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit">
<Grid>
<xctkToolkit:CheckListBox Name="m_myCheckBox"> <!-- Works fine -->
<xctkToolkit:CheckListBox/> <!-- Doesn't work -->
</xctkToolkit:CheckListBox>
</Grid>
</Window>
And I added the dependency Xceed.Wpf.Toolkit
to my project. The error I get is:
error MC3074: The tag 'CheckListBoxItem' does not exist in XML namespace 'clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit'
How do I solve this?
Upvotes: 1
Views: 2734
Reputation: 131728
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
Upvotes: 3