Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
765 views
in Technique[技术] by (71.8m points)

c# - WPF toolkit CheckListBox SelectedItemsOverride not working

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"}
};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try add Mode and UpdateSourceTrigger at binding

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...