SelectedItemsOverride不起作用

SelectedItemsOverride不起作用

本文介绍了WPF工具箱CheckListBox SelectedItemsOverride不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自wpf工具箱2的复选框。我无法获得所有选中的项目。我读到我应该使用SelectedItemsOverride来获取我所有选中的项目,但似乎不起作用。我在SetClass中为TestClassSelected设置了一个断点,但从未触发过。有任何想法吗?

I have a check list box from the wpf toolkit 2. I cannot get all of the selected items. I read that I am supposed to use SelectedItemsOverride to get all of my selected items but it does not seem to work. I put a break point in the setter for TestClassSelected but it is never fired. Any Ideas?

<xctk:CheckListBox Name="MyCheckList"
                   ItemsSource="{Binding TestClassCollection}"
                   DisplayMemberPath="DisplayName"
                   SelectedItemsOverride="{Binding TestClassSelected}"  />

public IEnumerable<TestClass> TestClassCollection
{
    get { return _testClassCollection; }
    set
    {
        _testClassCollection = value;
        OnPropertyChanged("TestClassCollection");
    }
}

public List<TestClass> TestClassSelected
{
    get { return _testClassSelected; }
    set
    {
        _testClassSelected = value;
        OnPropertyChanged("TestClassSelected");
    }
}

public class TestClass
{
    public String FirstName { get; set; }
    public String LastName { get; set; }

    public String DisplayName {
         get { return string.Format("{0} {1}", FirstName, LastName); }
    }
}

这是我一直在使用的测试数据。

This is my test data I have been using.

TestClassCollection = new List<TestClass>
{
    new TestClass {FirstName = "FIrstName", LastName = "LastName"},
    new TestClass {FirstName = "Brad", LastName = "Holder"},
    new TestClass {FirstName = "Sam", LastName = "Ryans"},
    new TestClass {FirstName = "Ryan", LastName = "Thomas"},
    new TestClass {FirstName = "Lee", LastName = "Rod"},
    new TestClass {FirstName = "Amanda", LastName = "Gustaf"},
    new TestClass {FirstName = "Chris", LastName = "Holems"},
    new TestClass {FirstName = "Doug", LastName = "Schnitzel"},
    new TestClass {FirstName = "Lisa", LastName = "Bull"},
    new TestClass {FirstName = "Fred", LastName = "Simpson"},
    new TestClass {FirstName = "Scott", LastName = "Rogers"}
};


推荐答案

尝试在绑定时添加Mode和UpdateSourceTrigger

try add Mode and UpdateSourceTrigger at binding

<xctk:CheckListBox Name="MyCheckList"
                   ItemsSource="{Binding TestClassCollection}"
                   DisplayMemberPath="DisplayName"
                   SelectedItemsOverride="{Binding TestClassSelected,
                          Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

更新:
我从封闭位置检查了示例代码在中发布。
尝试将TestClassSelected属性更改为ObservableCollection。 (仍然将上述UpdateSourceTrigger保留在.xaml中)。

update:I'd checked example code from closed issue at Extended WPF Toolkit CodePlex site.Try to change TestClassSelected property to ObservableCollection. (Still keep UpdateSourceTrigger described above in .xaml)

public ObservableCollection<TestClass> TestClassSelected

这篇关于WPF工具箱CheckListBox SelectedItemsOverride不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:52