UpdateSourceTrigger PropertyChanged on IsChecked Isn't Firing on ItemsSource of ListBox of Checkboxes

后端 未结 1 1189
礼貌的吻别
礼貌的吻别 2021-01-15 16:42

I have a listbox in which the item source contains a List(of T) that has a SelectedFlag boolean property. My viewmodel is set as the DataContext of my user control and ever

相关标签:
1条回答
  • 2021-01-15 17:09

    You'll need to make your Collection's CollectionChanged event fire when your Item's PropertyChanged event fires.

    Something like:

    MyCollection.CollectionChanged += MyCollectionChanged;
    

    ...

    void MyCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            foreach (object item in e.NewItems)
            {
                if (item is MyItem)
                    ((MyItem)item).PropertyChanged += MyItem_PropertyChanged;
            }
        }
    
        if (e.OldItems != null)
        {
            foreach (object item in e.OldItems)
            {
                if (item is MyItem)
                    ((MyItem)item).PropertyChanged -= MyItem_PropertyChanged;
            }
        }
    }
    

    ...

    void MyItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        OnPropertyChanged("MyCollection");
    }
    
    0 讨论(0)
提交回复
热议问题