using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using MaterialDesignColors.WpfExample.Domain; namespace MaterialDesignDemo.Domain { public class ListsAndGridsViewModel : INotifyPropertyChanged { private readonly ObservableCollection _items1; private readonly ObservableCollection _items2; private readonly ObservableCollection _items3; private bool? _isAllItems3Selected; public ListsAndGridsViewModel() { _items1 = CreateData(); _items2 = CreateData(); _items3 = CreateData(); } public bool? IsAllItems3Selected { get { return _isAllItems3Selected; } set { if (_isAllItems3Selected == value) return; _isAllItems3Selected = value; if (_isAllItems3Selected.HasValue) SelectAll(_isAllItems3Selected.Value, Items3); OnPropertyChanged(); } } private static void SelectAll(bool select, IEnumerable models) { foreach (var model in models) { model.IsSelected = select; } } private static ObservableCollection CreateData() { return new ObservableCollection { new SelectableViewModel { Code = 'M', Name = "Material Design", Description = "Material Design in XAML Toolkit" }, new SelectableViewModel { Code = 'D', Name = "Dragablz", Description = "Dragablz Tab Control", Food = "Fries" }, new SelectableViewModel { Code = 'P', Name = "Predator", Description = "If it bleeds, we can kill it" } }; } public ObservableCollection Items1 => _items1; public ObservableCollection Items2 => _items2; public ObservableCollection Items3 => _items3; public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public IEnumerable Foods { get { yield return "Burger"; yield return "Fries"; yield return "Shake"; yield return "Lettuce"; } } } }