using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.ComponentModel;

namespace SilverlightApplication106
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            testGrid.ItemsSource = TestItem.Generate(100);            
        }
   


        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            if ((sender as CheckBox).ParentOfType<GridViewCell>().IsInEditMode)
                (sender as CheckBox).ParentOfType<GridViewCell>().CommitEdit();
        }   
    }

    public class TestItem : INotifyPropertyChanged
    {
        private static Random rnd = new Random();
        private bool val2;
        public int Prop1 { get; set; }

        public bool Prop2
        {
            get
            {
                return val2;
            }
            set
            {
                val2 = value;
                OnPropertyChanged("Prop2");
            }
        }

        public TestItem()
        {
            Prop1 = rnd.Next(100);
            Prop2 = (rnd.Next(2) == 0) ? false : true;
        }

        public static ObservableCollection<TestItem> Generate(int count)
        {
            ObservableCollection<TestItem> res = new ObservableCollection<TestItem>();
            for (int i = 0; i < count; i++)
            {
                res.Add(new TestItem());
            }

            return res;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }
}
