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.ComponentModel;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;

namespace CalculatedColumns
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            List<Item> items = new List<Item>();

            items.Add(new Item(){ Name = "Item1", Count= 2, Price = 10 });
            items.Add(new Item() { Name = "Item2", Count = 5, Price = 20 });
            this.gridView.ItemsSource = items;
        }
    }

    public class Item : INotifyPropertyChanged
    {
        public string Name { get; set; }
        private decimal price;
        public decimal Price 
        {
            get
            {
                return this.price;
            }
            set
            {
                this.price = value;
                Recalculate();
            }
        }
        private int count;
        public int Count 
        {
            get
            {
                return this.count;
            }
            set
            {
                this.count = value;
                Recalculate();
            }
        }

        private decimal total;
        public decimal Total 
        {
            get
            {
                return this.total;
            }
            set
            {
                this.total = value;
                this.OnPropertyChanged("Total");
            }
        }

        private void Recalculate()
        {
            this.Total = this.Price * this.Count;
        }

        private void OnPropertyChanged(string property)
        {
            if( this.PropertyChanged!=null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(property));
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
