using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private List<ColumnWidthChangedListener> columnsData;


        private void ExampleGridView_Loaded(object sender, RoutedEventArgs e)
        {
            columnsData = new List<ColumnWidthChangedListener>();

            ExampleGridView.ItemsSource = new ObservableCollection<Person>
            {
               new Person(){FirstName="Name",LastName="LastName"},
               new Person(){FirstName="Name",LastName="LastName"},
               new Person(){FirstName="Name",LastName="LastName"},
               new Person(){FirstName="Name",LastName="LastName"},
               new Person(){FirstName="Name",LastName="LastName"},
               new Person(){FirstName="Name",LastName="LastName"},
               new Person(){FirstName="Name",LastName="LastName"}
            };

        }

        private void ExampleGridView_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
        {
            ColumnWidthChangedListener meta = new ColumnWidthChangedListener();
            meta.Column = e.Column;
            columnsData.Add(meta);

            Binding binding = new Binding("Width");
            binding.Source = e.Column;
            BindingExpressionBase bin = meta.SetBinding(ColumnWidthChangedListener.GridViewColumnWidthProperty, binding);
        }
    }

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string SecondName { get; set; }
    }
    public class ColumnWidthChangedListener:FrameworkElement
    {
        public Telerik.Windows.Controls.GridViewColumn Column { get; set; }

        public static readonly DependencyProperty GridViewColumnWidthProperty = DependencyProperty.Register("GridViewColumnWidth",
typeof(Telerik.Windows.Controls.GridViewLength),
typeof(ColumnWidthChangedListener),
new PropertyMetadata(new Telerik.Windows.Controls.GridViewLength(), OnColumnWidthChanging));

        public static void OnColumnWidthChanging(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Telerik.Windows.Controls.GridViewLength newValue = (Telerik.Windows.Controls.GridViewLength)e.NewValue;
            Telerik.Windows.Controls.GridViewLength oldValue = (Telerik.Windows.Controls.GridViewLength)e.OldValue;
            if (newValue.UnitType != newValue.UnitType || newValue.Value != oldValue.Value)
            {
                //raise other event if needed or apply custom logic
            }
        }
    }
}
