简体   繁体   English

扩展WPF Toolkit中的CheckListBoxItem不存在

[英]CheckListBoxItem in extended WPF Toolkit doesn't exist

I am using the Extended WPF Toolkit 2.0.0 to design a CheckListBox . 我正在使用Extended WPF Toolkit 2.0.0来设计CheckListBox I need to design checkbox items for it, but for some reason, the CheckListBoxItem doesn't exist. 我需要为它设计复选框项,但由于某种原因, CheckListBoxItem不存在。 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. 我将依赖Xceed.Wpf.Toolkit添加到我的项目中。 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' 错误MC3074:XML命名空间'clr-namespace中不存在标记'CheckListBoxItem':Xceed.Wpf.Toolkit; assembly = Xceed.Wpf.Toolkit'

How do I solve this? 我该如何解决这个问题?

Just use ListBoxItem . 只需使用ListBoxItem The CheckListBox control (and any ItemsContainer-derived control) isn't required to define its own item classes. CheckListBox控件(以及任何ItemsContainer派生的控件)不需要定义自己的项类。 You can use any ContentControl-derived class but ListBoxItem provides usefull properties like IsSelected. 您可以使用任何ContentControl派生类,但ListBoxItem提供有用的属性,如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. 更好的解决方案是将CheckListBox绑定到您自己的类的集合,并将绑定设置为类的属性。 In fact, this is shown in the description of the CheckListBox control itself . 实际上,这CheckListBox控件本身的描述中CheckListBox Just note that you have to bind SelectedItemsOverride to a list of selected items instead of SelectedItems 请注意,您必须将SelectedItemsOverride绑定到所选项的列表而不是SelectedItems

For example, assuming I have the following in my MainWindow.xaml.cs 例如,假设我在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: 我可以像这样创建一个CheckBoxList

<xctk:CheckListBox 
    ItemsSource="{Binding MyItems}" 
    SelectedItemsOverride="{Binding JustSelectedItems}" />

and each time I check/uncheck an item it is added or removed from JustSelectedItems. 每次我检查/取消选中一个项目时,它都会从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 通常,您将使用MVVM框架为每个控件设置正确的DataContext,但是对于这个简单的示例,我简单地告诉表单绑定到自身

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM