WPF toolkit CheckListBox SelectedItemsOverride not working

后端 未结 3 1928
臣服心动
臣服心动 2021-01-22 13:50

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 bu

3条回答
  •  一向
    一向 (楼主)
    2021-01-22 14:06

    I combined previous answers/comments and what worked for me was to bind SelectedItemsOverride to an ObservableCollection, include UpdateSourceTrigger=PropertyChanged, and attach a method to the ObservableCollection's event CollectionChanged.

    The XAML:

    
    
    

    Code in ViewModel:

    public IEnumerable AllItems { get; set; }
    
    public ObservableCollection SelectedItems { get; set; }
    
    public ViewModel()
    {
        SelectedItems = new ObservableCollection();
    
        SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
    }
    
    private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        // Handle collection changed event
    }
    

提交回复
热议问题