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;
using System.Windows.Data;

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

        }
    }

    public class MyCheckBoxColumn : GridViewCheckBoxColumn
    {
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            var element = base.CreateCellEditElement(cell, dataItem);
            (element as CheckBox).SetBinding(CheckBox.IsCheckedProperty, new Binding("Prop2") { Source = dataItem, Mode= BindingMode.TwoWay });
            return element;
        }
    }

    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
            {
                if (val2 != value)
                {
                    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));
            }
        }
    }
}
