using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace CheckboxSelectAll
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }


        private void chkBox_Checked(object sender, RoutedEventArgs e)
        {

            foreach (var item in clubsGrid.Items)
            {
                if (!((Club)item).IsDisabled)
                {
                    this.clubsGrid.SelectedItems.Add(item);

                }
              
            }
        }

        private void chkBox_Unchecked(object sender, RoutedEventArgs e)
        {
            foreach (var item in clubsGrid.Items)
            {
                if (!((Club)item).IsDisabled)
                {
                    this.clubsGrid.SelectedItems.Remove(item);
                }
            }
        }

        private void clubsGrid_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
        {
            foreach (var item in e.AddedItems)
            {
                ((Club)item).IsSelected = true;
            }
            foreach (var item in e.RemovedItems)
            {
                ((Club)item).IsSelected = false;
            }
        }
    }
}
