WPF MVVM: Listview checkbox header for selecting/unselecting all the listview items

前端 未结 1 906
我寻月下人不归
我寻月下人不归 2021-01-27 11:44

I am trying to select/unselect all the listview items when checkbox in listview header is clicked.

View (xaml):

            

        
相关标签:
1条回答
  • 2021-01-27 12:19

    Your class DataModel must implement INotifyPropertyChanged, and fire the PropertyChanged event when the IsSelected property changes. Otherwise, the Binding of the ListViewItem's IsSelected property isn't notified.

    public class DataModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        private bool isSelected;
        public bool IsSelected
        {
            get { return isSelected; }
            set
            {
                isSelected = value;
                PropertyChanged?.Invoke(this,
                    new PropertyChangedEventArgs(nameof(IsSelected)));
            }
        }
    
        public string ID { get; set; }
        public string Desc { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题